Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to check if player isn't clicking button??

Hi I am wondering how can I code my code to know when a player isn't clicking on my gui button

Example of player clicking button now how can I check if they aren't??

script.parent.Mousebutton1clickdown:connect(function()

end)

Hope you understand what I mean very hard to explain

Thanks

Sound script

local Button = script.Parent



local Clicked = false



Button.MouseButton1Down:Connect(function()

	Clicked = true



	while Clicked do

		game.ReplicatedStorage.Sound:FireServer()

		wait(.2)

	end

	game.ReplicatedStorage.Soundstop:FireServer()

end)



Button.MouseButton1Up:Connect(function()

	Clicked = false

end)

1 answer

✓ Accepted answer

You can use a variable to determine if the player is clicking the button; if the variable is false, the player is not clicking the button.

local Button = script.Parent
local Sound = script.Parent.Sound

local Clicked = false

Button.MouseButton1Down:Connect(function()
	Clicked = true
	
	while Clicked do
		Sound:Play()
		Sound.Ended:Wait()
	end
	Sound:Stop()
end)

Button.MouseButton1Up:Connect(function()
	Clicked = false
end)

4 comments

0

not quite what I wanting I got a sound system and the player holds the button to play sound. Soon as they let go of the button I want to sound to stop

0

I just tested it with your code and it didn't work

0

It would work, you just need to modify it to work with your code.

0

Thank you it works!! Though with the system I got to play the sound there is a cut if you know how to fix that I updated my post if not still this works perfectly so thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.