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

How do i create a debounce in this giver script?

local passId =  389373250 -- Change this to your game pass' ID
local GPS = game:GetService("GamePassService")
local lighting = game.Lighting
local hmg  = {lighting.HMG, lighting.GHMG}

script.Parent.Touched:connect(function(part)
if game.Players:FindFirstChild(part.Parent.Name) then
local player  = game.Players[part.Parent.Name]
if GPS:PlayerHasPass(player, passId)  then
if player.Backpack:FindFirstChild(hmg[2].Name)==nil or 						player.StarterGear:FindFirstChild(hmg[2].Name)==nil then
hmg[2]:Clone().Parent = player.Backpack
hmg[2]:Clone().Parent = player.StarterGear
else
 if player.Backpack:FindFirstChild(hmg[1].Name)==nil and 	player.StarterGear:FindFirstChild(hmg[1].Name)==nil then
hmg[1]:Clone().Parent = player.Backpack
hmg[1]:Clone().Parent = player.StarterGear
end
end
end
end
end)

I'm trying to make a debounce using this script

1 answer

✓ Accepted answer

At the top of the script make a variable

local using = false

At the start of the Touched event write

if using == false then -- you could use `not using` instead
	using = true
	--do stuff
end

Then hook it up to a TouchEnded event:

script.Parent.TouchEnded:connect(function(part)
	using = false
end)

1 comment

0

Thanks!

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