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

Can someone help with this broken script? It would be a "kill all" script.

local victims = game.Players:GetPlayers()``
script.Parent.MouseButton1Click:Connect(function()
    for i, victims in pairs(victims) do
        local char = victims.Character
		local humanoid = char:FindFirstChild("Humanoid")
        if humanoid then
            humanoid.Health = 0
        end
    end
end)

I think the "for i, victims in pairs(victims) do" is the broken part, because as soon as I tried to print something it didn't work. Thank you all!

2 comments

0

Btw this is a button to kill everyone in the server.

0

On line 3 throughout the whole for loop you are overwriting the victims variable. So I recommend you change it to for i, victim

1 answer

✓ Accepted answer
script.Parent.MouseButton1Click:Connect(function()
	local victims = game.Players:GetPlayers() --Always put this within the function.
	for _, victim in pairs(victims) do --Note that I used "victim" instead of "victims." Always give different variables a different name so that it doesn't confuse you, and in most cases, the computer.
		local char = victim.Character
		local humanoid = char:FindFirstChild("Humanoid")
		if humanoid then
			humanoid.Health = 0
		end
	end
end)

Try this and see if it works.

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