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 4 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.

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

Log in to vote
3
Answered by 4 years ago
Edited 4 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

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
0
Well said. Utter_Incompetence 856 — 4y
0
this did not work with no error Sadwowow21 57 — 4y
0
OK it weird now. Block_manvn 395 — 4y
0
Wait, do you put ClickDetector to the part. Block_manvn 395 — 4y
View all comments (4 more)
0
Where is the script located? Is it in the button, or where? XxOPGUYxX1234567 221 — 4y
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 — 4y
0
If it still doesn't work, make sure the script is inside of the button that you're clicking. XxOPGUYxX1234567 221 — 4y
0
in the button Sadwowow21 57 — 4y
Ad

Answer this question