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

Is there a way to stop Screen GUI button spamming?

Asked by
DBoi941 57
5 years ago

Is there a way to slow down the player from pushing the button real fast like a delay?

local Main = script.Parent:FindFirstChild('Main')
local Test = Main.Glass:FindFirstChild('Test') -- This is a screen gui Button

Test.MouseButton1Down:connect(function()
    local rS = game:GetService("ReplicatedStorage")
    local remote = rS.EventsBlocks:WaitForChild("Test1")
    remote:FireServer()
end)

1 answer

Log in to vote
0
Answered by 5 years ago

you need a debounce and to get that you type the following

debounce = false
if not debounce then
debounce = true
wait(the time u want to wait in here)
debounce = true

here is the full script if u dont understand

local Main = script.Parent:FindFirstChild("Main")
local Test = Main.Glass:FindFirstChild("Test")
    debounce = false
    Test.MouseButton1Down:Connect(function()
    if not debounce then--this will see if debounce is false and if it is then it will run
    debounce = true--this sets the debounce to true so the function cant be run again
        local rS = game:GetService("ReplicatedStorage")
        local remote = rS.EventsBlocks:WaitForChild("Test1")
        remote:FireServer()
        wait(time in here)
        debounce = false--after the time set debounce will return to false so the function can run
    end)

also when you attempt to find the first child you dont use ' instead you use "

0
I understand now thank you very much. Also thank for the tip about ' and " DBoi941 57 — 5y
0
happy to help, im also learning lua from this site and yt vids so im happy to help Gameplayer365247v2 1055 — 5y
Ad

Answer this question