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

Kill all players button not working?

I tried making a thing where once you click a button it kills every player. It doesn't work and here is my code.

function leftClick(mouse)
	 for i, player in ipairs(game.Players:GetPlayers()) do
	if player.Character then
		local hum = player.Character:FindFirstChild('Humanoid')
		if hum then
			hum.Health = 0
		end	
end
end

1 answer

✓ Accepted answer

First, you're not calling the function. You made the function but you haven't called it yet. If you would place the script inside of the button, this would be the function

function leftClick() --There's no need to have "Mouse"
	    for i, player inpairs(game.Players:GetPlayers()) do --I would use inpairs instead of ipairs
	   if player.Character then
	       local hum = player.Character:FindFirstChild('Humanoid')
	       if hum then
	           hum.Health = 0
	        end
	end
end
end

We would call the function like this:

script.Parent.MouseButton1Click:Connect(leftClick) --This calls the function when someone left clicks the button

Full Script:

function leftClick() --There's no need to have "Mouse"
	    for i, player in pairs(game.Players:GetPlayers()) do --I would use in pairs instead of ipairs
	   if player.Character then
	       local hum = player.Character:FindFirstChild('Humanoid')
	       if hum then
	           hum.Health = 0
	        end
	end
end
end

script.Parent.MouseButton1Click:Connect(leftClick) --This calls the function when someone left clicks the button

8 comments

0

Well said.

0

this did not work with no error

0

OK it weird now.

0

Wait, do you put ClickDetector to the part.

0

Where is the script located? Is it in the button, or where?

0

Try it now. I forgot to add an end. Also, I tested it in studio with the script inside of the button and it worked.

0

If it still doesn't work, make sure the script is inside of the button that you're clicking.

0

in the button

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