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

How do i create a debounce in this giver script?

Asked by 9 years ago
01local passId =  389373250 -- Change this to your game pass' ID
02local GPS = game:GetService("GamePassService")
03local lighting = game.Lighting
04local hmg  = {lighting.HMG, lighting.GHMG}
05 
06script.Parent.Touched:connect(function(part)
07if game.Players:FindFirstChild(part.Parent.Name) then
08local player  = game.Players[part.Parent.Name]
09if GPS:PlayerHasPass(player, passId)  then
10if player.Backpack:FindFirstChild(hmg[2].Name)==nil or                      player.StarterGear:FindFirstChild(hmg[2].Name)==nil then
11hmg[2]:Clone().Parent = player.Backpack
12hmg[2]:Clone().Parent = player.StarterGear
13else
14 if player.Backpack:FindFirstChild(hmg[1].Name)==nil and    player.StarterGear:FindFirstChild(hmg[1].Name)==nil then
15hmg[1]:Clone().Parent = player.Backpack
View all 21 lines...

I'm trying to make a debounce using this script

1 answer

Log in to vote
2
Answered by 9 years ago

At the top of the script make a variable

1local using = false

At the start of the Touched event write

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

Then hook it up to a TouchEnded event:

1script.Parent.TouchEnded:connect(function(part)
2    using = false
3end)
0
Thanks! Supergamerboy1995 129 — 9y
Ad

Answer this question