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

I tried adding a debounce to this script now it's not working help, ?

So this is my original script:

boxOwn = script.Parent
boxOwn.Touched:connect(function(part)
	local Player = game.Players:GetPlayerFromCharacter(part.Parent)
	game.Lighting["Box"]:clone().Parent = Player.Backpack 
end)

However that made it so when a player touches the box it gives them like 20 boxes. So I did this:

boxOwn = script.Parent
boxOwn.Touched:connect(function(part)
	if not debounce then
		debounce = true
		local plyr = game.Players:GetPlayerFromCharacter(part.Parent)
		game.Lighting["Box"]:clone().Parent = plyr.Backpack
	end
	wait(2)
end)
debounce = false

I tried adding a debounce and it works once but you cant get any boxes after that

1 answer

✓ Accepted answer
boxOwn = script.Parent
boxOwn.Touched:connect(function(part)
    if not debounce then
        debounce = true
        local plyr = game.Players:GetPlayerFromCharacter(part.Parent)
        game.Lighting["Box"]:clone().Parent = plyr.Backpack
    end
    wait(2)
end)
debounce = false

Debounce was never called again. Because you ended the function before it turned it off. Its as simple as doing this

boxOwn = script.Parent
boxOwn.Touched:connect(function(part)
    if not debounce then
        debounce = true
        local plyr = game.Players:GetPlayerFromCharacter(part.Parent)
        game.Lighting["Box"]:clone().Parent = plyr.Backpack
    wait(2)
debounce = false    
end
end)

1 comment

0

Erm lemme just correct myself XD thanks to TheeDeathCaster... You should move the wait and debounce before the end XD

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