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

How to add a cooldown to this NPC chat?

Asked by 5 years ago
Edited 5 years ago
function onClick(click)
for i,v in pairs (script.Parent:GetChildren()) do
    if v.ClassName == "ScreenGui" then
    c = v:Clone()
    c.Parent = click.PlayerGui
    end
end
end
script.Parent.ClickDetector.MouseClick:connect(onClick)

How would I add a cooldown to this? https://gyazo.com/1a50b42fd23c99c0c32e1090132af3c1 - Inside of it Script i'm showing up here - https://gyazo.com/d116ff7d6e0d6a75acec3f05be34c5ac The script that might be causing the issues - https://gyazo.com/5ce102653073a10c0cf71d0e9b6c795f

0
use a debounce theking48989987 2147 — 5y

1 answer

Log in to vote
0
Answered by
IDKBlox 349 Moderation Voter
5 years ago
Edited 5 years ago

For this, you're going to want to use a debounce as theking48989987 commented on your post. To do this you just need a simple true or false statement

local debounce = false -- Saying it's not being used
function onClick(click)
    if debounce == false then debounce = true -- Checking if it's not being used, and if it's not, setting it to being used!
        for i,v in pairs (script.Parent:GetChildren()) do
            if v.ClassName == "ScreenGui" then
                c = v:Clone()
                c.Parent = click.PlayerGui
            end
        end
        wait(3) -- waiting 3 seconds
        debounce = false -- Setting it back to not being used, therefor it can be used again
    end
end
script.Parent.ClickDetector.MouseClick:connect(onClick)
0
For some reason this cause's the script to be unusable DN_Mythic 11 — 5y
0
There's also another script if this is causing it be unusable DN_Mythic 11 — 5y
0
that makes no sense lol. All I did was take your script and add a deounce for 3 seconds lol. meaning the button will only work every 3 seconds IDKBlox 349 — 5y
0
I don't know.. :shrug: DN_Mythic 11 — 5y
View all comments (10 more)
0
I could show you images of what it is? DN_Mythic 11 — 5y
0
Did it work before? if so, then click on it wait 3 seconds then try to click on it again and see if it works IDKBlox 349 — 5y
0
Sure IDKBlox 349 — 5y
0
What's your discord or am I allowed to post gyazo images here? DN_Mythic 11 — 5y
0
Yes you are allowed to post gyazo images, just edit your post and place it there IDKBlox 349 — 5y
0
Alright DN_Mythic 11 — 5y
0
I put the gyazos DN_Mythic 11 — 5y
0
I just edited my script, Try it again IDKBlox 349 — 5y
0
Works! Thanks. DN_Mythic 11 — 5y
0
No problem, could you accept my answer please? IDKBlox 349 — 5y
Ad

Answer this question