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

Why won't this kill script work? :C

function Fire()
	print("Slow Kill!")
	local players = game.Players:GetChildren()
	for i=1,#players do
		if players[i].Character ~= nil then 
			print("...")
			players[i].Character.Humanoid.Health:TakeDamage(1)
			end
			end
			end

while wait(.5) do
Fire()
end

Also, can you please see if there is a more efficient way of doing this? There probably is and i'm just stupid.

2 answers

✓ Accepted answer
players[i].Character.Humanoid.Health:TakeDamage(1)

You use TakeDamage() on the Humanoid, not the health. So

players[i].Character.Humanoid:TakeDamage(1)

1 comment

0

It still won't work...

function Fire()
    print("Kill em all!")
    local players = game.Players:GetChildren()
    for i=1,#players do
        if players[i].Character ~= nil then 
            print("...")
            players[i].Character.Humanoid.Health:TakeDamage(100) --simple mistake
            end
            end
            end

while wait(.5) do
Fire()
end

It works but you're only making them take 1 damage. When you need 100 to kill.

And for a more efficient method I would do this:

function Fire()
	for i, v in pairs(game.Players:GetChildren() do
		if v.Character then
			v.Character.Humanoid.Health = 0
		end
	end
end

while wait(.5) do 
	Fire()
end

now for a slow death:

function Fire()
	for i, v in pairs(game.Players:GetChildren() do
		if v.Character then
			repeat v.Character.Humanoid.Health = v.Character.Humanoid.Health - 1
				wait(.1)
			until v.Character.Humanoid.Health = 0 -- may be a double = im not sure. I don't use repeats alot
		end
	end
end

while wait(.5) do 
	Fire()
end

6 comments

0

Oops, I wanted it to kill them instantly, but then I wanted them to have a slow death...

0

Ohh if you want that you can use a repeat until. I will add it so you can see

0

Edited

0

Thanks! I'll test it out.

0

I saw some mistakes, like at line 2. (game.Players:GetChildren(). You need another ")". And at line 6. You need "==". You use "==" if you are comparing something. The health regen also made it slower. I deleted it. Thanks again!

0

Ummm... It won't loop. After the player dies, it stops.

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