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

WHy is there a syntax error Here now?

Asked by
IcyEvil 260 Moderation Voter
10 years ago

I just need to know why this Syntax error is here.

while wait() do
    health = {10, 15, 25, 40, 45, 60, 34, 26, 67, 78, 93, 100}
    end
    for _,v in pairs(game.Players:GetChildren())do
local function kill()
    local humanoid = v.Character:findFirstChild("Humanoid")
    if humanoid then
        humanoid.Health = (1, 12 #health)-- Now it says I need another ')' before 1 For Who Knows what reason..., Syntax Error Under ','

end
end
end
end
0
What are you trying to do on line 8? Pick a random health from the list of values? If so, you should be using math.random Merely 2122 — 10y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

First of all, tab and space your code properly.

while wait() do
    health = {10, 15, 25, 40, 45, 60, 34, 26, 67, 78, 93, 100}
end

for _,v in pairs(game.Players:GetChildren()) do
    local function kill()
        local humanoid = v.Character:findFirstChild("Humanoid")
        if humanoid then
            humanoid.Health = (1, 12 #health)
        end
    end
end
end

Looking at the last lines (and also examining the loop at the top) we can see you definitely have your blocks not closed neatly.

It should look like this*:

while wait() do
    health = {10, 15, 25, 40, 45, 60, 34, 26, 67, 78, 93, 100}
    for _,v in pairs(game.Players:GetChildren()) do
        local function kill()
            local humanoid = v.Character:findFirstChild("Humanoid")
            if humanoid then
                humanoid.Health = (1, 12 #health)
            end
        end
    end
end

Now looking at the humanoid.Health line.

I'm not sure exactly what you were trying to do here.

To kill the humanoid, just set the Health property to 0:

                humanoid.Health = 0

To pick a random element from health, it will look like this:

                humanoid.Health = health[ math.random(1,#health) ]

Nonetheless, you never call your kill() function.


It does not make sense to define kill inside of the loop. In general, this is a very bad idea. Define it outside of the loop and use a parameter:

function kill(player)
    local humanoid = player.Character:findFirstChild("Humanoid")
    if humanoid then
        humanoid.Health = 0
    end
end

while wait() do
    for _,v in pairs(game.Players:GetChildren()) do

    end
end

Now, you should also remember that player.Character can be nil, and should check for that too:

function kill(player)
    if player.Character then
        local humanoid = player.Character:findFirstChild("Humanoid")
        if humanoid then
            humanoid.Health = 0
        end
    end
end
Ad

Answer this question