So, I have this code on multiple parts that checks if a player already has a forcefield. If they don't, they are given one. Then, on another part I have a code that checks if a player has one, then removes it. But, sometimes I have a random forcefield spawning at 0, 0, 0. I don't know why this is. Any ideas?
Here are my 2 different codes:
script.Parent.Touched:connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then if not player.Character:FindFirstChild("ForceField") and player.Character.Humanoid then local ff = Instance.new("ForceField", player) end end end)
You probably need to check if hit.Parent is a character. You can do this by checking for a Humanoid, or by using :GetPlayerFromCharacter()
.
script.Parent.Touched:connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) ~= nil then if not hit.Parent:FindFirstChild("ForceField") then local ff = Instance.new("ForceField", hit.Parent) end end end)
Hope this helped.
I suggest that if you don't want a forcefield occur you do the following; Select your spawnlocation Go to its properties and find the Forcefield tab, make sure the duration is 0, or however long you want. If it is 0 it won't give the player that spawns there a forcefield.