Ad
Log in to vote
1

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

Asked by 18 days ago
Edited 17 days 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 18 days ago
Edited 17 days 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 757 — 17d
0
I just tested it with your code and it didn't work theking66hayday 757 — 17d
0
It would work, you just need to modify it to work with your code. xInfinityBear 1711 — 17d
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 757 — 17d
Ad

Answer this question