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

Kill all players button not working?

Asked by 5 years ago

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

1function leftClick(mouse)
2     for i, player in ipairs(game.Players:GetPlayers()) do
3    if player.Character then
4        local hum = player.Character:FindFirstChild('Humanoid')
5        if hum then
6            hum.Health = 0
7        end
8end
9end

1 answer

Log in to vote
3
Answered by 5 years ago
Edited 5 years ago

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

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

We would call the function like this:

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

Full Script:

01function leftClick() --There's no need to have "Mouse"
02        for i, player in pairs(game.Players:GetPlayers()) do --I would use in pairs instead of ipairs
03       if player.Character then
04           local hum = player.Character:FindFirstChild('Humanoid')
05           if hum then
06               hum.Health = 0
07            end
08    end
09end
10end
11 
12script.Parent.MouseButton1Click:Connect(leftClick) --This calls the function when someone left clicks the button
0
Well said. Utter_Incompetence 856 — 5y
0
this did not work with no error Sadwowow21 57 — 5y
0
OK it weird now. Block_manvn 395 — 5y
0
Wait, do you put ClickDetector to the part. Block_manvn 395 — 5y
View all comments (4 more)
0
Where is the script located? Is it in the button, or where? XxOPGUYxX1234567 221 — 5y
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. XxOPGUYxX1234567 221 — 5y
0
If it still doesn't work, make sure the script is inside of the button that you're clicking. XxOPGUYxX1234567 221 — 5y
0
in the button Sadwowow21 57 — 5y
Ad

Answer this question