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

Force field giver gives too many force field?

Asked by
otto045 41
6 years ago

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

Log in to vote
0
Answered by
522049 152
6 years ago

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
0
Thank :D otto045 41 — 6y
Ad

Answer this question