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

Why is this simple forcefeild script not working? It gives the output "'then' expected near <eof>"

Asked by 6 years ago

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?

0
try putting .Parent in another lines MineBlow111 39 — 6y
0
Delete the “if” on line 1 in both scripts. User#20279 0 — 6y
0
Thank you Denny that was a stupid mistake I don't know why I did that FirestormFury 7 — 6y
0
And I just realized that I spelled forcefield wrong FirestormFury 7 — 6y

3 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Remove the ")" from "end" on both scripts.

Ad
Log in to vote
0
Answered by 6 years ago
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"

Log in to vote
0
Answered by 6 years ago

You have multiple errors.

  1. Remove the "if" on the first line of code.

  2. You're using :connect when it's :Connect.

  3. In your second line, you didn't add a :FindFirstChild.

  4. 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)

Answer this question