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

Force field giver gives too many force field?

Hello, I made a forcefield giver, so when the player is up at spawn, he has a force field. And when he jumps down it takes he's forcefield from him again. But right now when he spawns, he gets like 20 force fields, and it looks really dumb, I have tried to use debounce, but I do not know if I did it correctly.

Code I use

local debounce = false 
function onTouched(part)
	local h = part.Parent:findFirstChild("Humanoid")
	if h~=nil and debounce == false then
		debounce = true
		Field = Instance.new("ForceField")
		Field.Parent = part.Parent
		debounce = false
		wait(4)
	end
	end

if (script.Parent ~= nil) and (script.Parent.className == "Part") then 
	connection = script.Parent.Touched:connect(onTouched)
end

1 answer

✓ Accepted answer

You have to check if they have a forcefield already, so rewrite line 4 like this

if h~=nil and debounce == false and not h.Parent:FindFirstChild("ForceField") then

1 comment

0

Thank :D

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