found a fishing minigame script but am trying to figure out how to make it so it only activates when someone presses the proximity prompt i set up for it

Help

heres the script.

local TweenService = game:GetService("TweenService")

local UserInputService = game:GetService("UserInputService")

local RunService = game:GetService("RunService")

local fishGame = script.Parent

local mainFrame = fishGame:WaitForChild("MainFrame")

local movingNeedle = mainFrame:WaitForChild("MovingNeedle")

local movingButton = mainFrame:WaitForChild("MovingButton")

local successSound = script:WaitForChild("SuccessSound")

local failSound = script:WaitForChild("FailSound")

local reelSound = script:WaitForChild("ReelSound")

local trumpetSound = script:WaitForChild("TrumpetSound")

local gameDuration = 20 -- seconds

local score = 0

local gameActive = false

-- For MovingButton physics

local buttonPos = 0

local buttonVelocity = 0

local leftBound = 0

local rightBound = mainFrame.AbsoluteSize.X - movingButton.AbsoluteSize.X

-- Function to continuously move the needle randomly within MainFrame bounds.

local function moveNeedleLoop()

while gameActive do

	local tweenTime = math.random(1, 2)

	local maxNeedleX = mainFrame.AbsoluteSize.X - movingNeedle.AbsoluteSize.X

	local newX = math.random(0, maxNeedleX)

	local tweenInfo = TweenInfo.new(tweenTime, Enum.EasingStyle.Linear)

	local goal = {Position = UDim2.new(0, newX, movingNeedle.Position.Y.Scale, movingNeedle.Position.Y.Offset)}

	local tween = TweenService:Create(movingNeedle, tweenInfo, goal)

	tween:Play()

	tween.Completed:Wait()

end

end

local function startGame(duration, pointsNeeded)

gameDuration = duration

fishGame.Enabled = true

gameActive = true

score = 0

buttonPos = leftBound

buttonVelocity = 0

movingButton.Position = UDim2.new(0, buttonPos, movingButton.Position.Y.Scale, movingButton.Position.Y.Offset)

spawn(moveNeedleLoop)

local startTime = tick()

local connection

connection = RunService.RenderStepped:Connect(function(dt)

	if not gameActive then

		connection:Disconnect()

		return

	end

	if tick() - startTime >= gameDuration then

		gameActive = false

		print("Game Over! Score: " .. math.floor(score))

		if math.floor(score) >= pointsNeeded then

-- This is the condition for winning the game

trumpetSound:Play()

		else

-- This is the condition for failing the game

failSound:Play()

		end

		fishGame.Enabled = false

		return

	end



	local targetPos = leftBound 

	local springConstant = 3  

	local damping = 2

	local acceleration = -springConstant \* (buttonPos - targetPos) - damping \* buttonVelocity

	buttonVelocity = buttonVelocity + acceleration \* dt

	buttonPos = buttonPos + buttonVelocity \* dt



	if buttonPos < leftBound then

		buttonPos = leftBound

		buttonVelocity = 0

	elseif buttonPos > rightBound then

		buttonPos = rightBound

		buttonVelocity = 0

	end



	movingButton.Position = UDim2.new(0, buttonPos, movingButton.Position.Y.Scale, movingButton.Position.Y.Offset)



	local buttonLeft = movingButton.AbsolutePosition.X

	local buttonRight = buttonLeft + movingButton.AbsoluteSize.X

	local needleLeft = movingNeedle.AbsolutePosition.X

	local needleRight = needleLeft + movingNeedle.AbsoluteSize.X



	if buttonRight >= needleLeft and buttonLeft <= needleRight then

		score = score + dt  

		if not successSound.IsPlaying then

successSound:Play()

		end

	else

		successSound:Stop() 

	end

end)

end

UserInputService.InputBegan:Connect(function(input, gameProcessed)

if gameProcessed or not gameActive then return end



if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then

	buttonVelocity = buttonVelocity + 500 

	reelSound:Play()

	local originalSize = movingButton.Size

	local enlargedSize = UDim2.new(originalSize.X.Scale, originalSize.X.Offset + 10, originalSize.Y.Scale, originalSize.Y.Offset)

	local bounceTween = TweenService:Create(movingButton, TweenInfo.new(0.1, Enum.EasingStyle.Bounce), {Size = enlargedSize})

	bounceTween:Play()

	bounceTween.Completed:Wait()

	local returnTween = TweenService:Create(movingButton, TweenInfo.new(0.1, Enum.EasingStyle.Bounce), {Size = originalSize})

	returnTween:Play()

end

end)

startGame(20, 10)

Posted Dec 10, 2025, 3:01 PM UTC

13
Loading comments…