Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 1 year ago
Edited 1 year ago

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

Log in to vote
3
Answered by 1 year ago
Edited 1 year ago

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)
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 theking66hayday 841 — 1y
0
I just tested it with your code and it didn't work theking66hayday 841 — 1y
0
It would work, you just need to modify it to work with your code. xInfinityBear 1777 — 1y
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 theking66hayday 841 — 1y
Ad

Answer this question