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

How to add a cooldown to this NPC chat?

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

1 comment

0

use a debounce

1 answer

✓ Accepted answer

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)

14 comments

0

For some reason this cause's the script to be unusable

0

There's also another script if this is causing it be unusable

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

0

I don't know.. :shrug:

0

I could show you images of what it is?

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

0

Sure

0

What's your discord or am I allowed to post gyazo images here?

0

Yes you are allowed to post gyazo images, just edit your post and place it there

0

Alright

0

I put the gyazos

0

I just edited my script, Try it again

0

Works! Thanks.

0

No problem, could you accept my answer please?

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