Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Script keeps getting an "Then expected near end" and the last end is underlined in red, help?

Asked by 6 days ago

This script is not a script I created, it was a script somebody answered a question of mine with.

spikey = game.Workspace.Spikes:GetChildren() 

for i, v in pairs(spikey) do 
    if v.Touched:Connect(function(hit)
        if hit.Name == "Balloon" then
            game.Players.LocalPlayer.Character.Humanoid.Health = 0
    end
end)
end

for some reason, the last end is underlined and red and when I play it, it says "Then expected near end." What is that supposed to mean? And if I delete the end, the other end is screwed up too. What do I do? Put half an end?

0
add an extra end after line 6. Diezel_1K 73 — 6d

1 answer

Log in to vote
0
Answered by
Kiriot22 2737 Moderation Voter Community Moderator
6 days ago
Edited 6 days ago

You put an if before the connection by accident.

Here's the fixed code:

spikey = game.Workspace.Spikes:GetChildren() 

for i, v in pairs(spikey) do 
    v.Touched:Connect(function(hit)
        if hit.Name == "Balloon" then
            game.Players.LocalPlayer.Character.Humanoid.Health = 0
        end
    end)
end

Btw my advice: use local variables, and define the local player as one aswell.

0
Okay! Thank you! proGamergirl2468 14 — 6d
Ad

Answer this question