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