I am trying to get a forcefeild for all players in one room, and then turn it off when they leave that room. This script is attached to the floor of the room, I tried it in two different ways:
if script.Parent.Touched:connect(function(hit) if hit.Parent.Humanoid then game.ReplicatedStorage.ForceField:Clone().Parent = hit.Parent end end)
(I put a 'ForceFeild' in ReplicatedStorage)
if script.Parent.Touched:connect(function(hit) if hit.Parent.Humanoid then Instance.new("ForceFeild").Parent = hit.Parent end end)
Does anyone know why it is not working?
Remove the ")" from "end" on both scripts.
if script.Parent.Touched:connect(function(hit) if hit.Parent.Humanoid then Instance.new("ForceField").Parent = hit.Parent end end)
Do that, you misspelled "ForceField" you put "ForceFeild"
You have multiple errors.
Remove the "if" on the first line of code.
You're using :connect when it's :Connect.
In your second line, you didn't add a :FindFirstChild.
You misspelt "ForceField"
I will rewrite your code, working, no deprecated code, no errors.
-- I also added so you can script.Parent.Touched:Connect(function(part) if part.Parent:FindFirstChild"Humanoid" then if not part.Parent:FindFirstChildOfClass"ForceField" then local ff = Instance.new("ForceField",part.Parent) -- Done end end end)