My forcefield giver doesnt give the forcefield when a player touches it. I want it to check if a player already has a forcefield. If they don't, it gives them one.
script.Parent.Touched:connect(function(hit) local h = hit.Parent:FindFirstChild("Humanoid") if h.Parent:FindFirstChild("ForceField") == nil then local ff = Instance.new("ForceField") ff.Parent = h end end)
You're parenting the ForceField to the Humanoid instead of the Character Model. As well, you never actually check if h
is not nil
:
script.Parent.Touched:connect(function(hit) local h = hit.Parent:FindFirstChild("Humanoid") if h and not hit.Parent:FindFirstChild("ForceField") then Instance.new("ForceField", hit.Parent) end end)
The problem is that you need to make sure hit
is nil by using ~=nil
****FINAL CODE
function onTouched(hit) local h = hit.Parent:findFirstChild("Humanoid") if h ~= nil then local f = Instance.new("ForceField") f.Parent = hit.Parent end end script.Parent.Touched:connect(onTouched)