I tried making a thing where once you click a button it kills every player. It doesn't work and here is my code.
1 | function 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 |
8 | end |
9 | end |
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
01 | function 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 |
09 | end |
10 | end |
We would call the function like this:
1 | script.Parent.MouseButton 1 Click:Connect(leftClick) --This calls the function when someone left clicks the button |
Full Script:
01 | function 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 |
09 | end |
10 | end |
11 |
12 | script.Parent.MouseButton 1 Click:Connect(leftClick) --This calls the function when someone left clicks the button |