Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

WHy is there a syntax error Here now?

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

1 comment

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

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.