So i have a script here that’s supposed to kill off all the players in the server. But the script doesnt work. Its a server script. I have already tried waitforchild and findfirstchild, doesnt work. I get this error message:
Players.trueblockhead101.PlayerGui.Countdown.TextLabel.Script:72: attempt to index nil with ‘Humanoid’
Which i think it belives that humanoid doesnt exist but i can ensure you that it does.
local plr2 = plr.Character.Humanoid
plr2.Health = 0
plr is game.Players:GetPlayers()
local plr2 = plr.LocalPlayer.Character.Humanoid
How exactly are you killing each player? Are you looping through players in a player list?
But if you are trying to kill everyone, a simpler way would be to do this:
for i,v in pairs(game.Players:GetChildren()) do
v.Character.Humanoid.Health = 0
Doesn’t work on server scripts, only on local scripts, and I doubt they’re using a local script.
For the Players service you should use :GetPlayers() instead of GetChildren().
That variable is a table. If you wanna kill a specific player, do
local player = game.Players:FindFirstChild("player name") then set their health to 0.
Can you maybe show more of the script so we can tell where you’re getting the
plr variable from?
Hey! You can simply use something like this:
for i, v in pairs (game:GetService("Players"):GetPlayers()) do
v.Character:FindFirstChild("Humanoid").Health = 0
Hope this helps!
Hey! it works! thanks. Sorry I couldnt respond earlier. Could you explain the whole for i, v in pairs works? I see it everywhere yet dont know what id does…
i stands for the number in which the v (value) was found.
It simply loops through everything in a table.
It loops through everything inside of
game:GetService("Players"):GetPlayers(), i is just the variable for how many times it loops, as in how many players there are in the server, and the v is the instance that it looped to, basically just the player in this scenario. For example you could do:
for playerCount, player in ipairs(game:GetService("Players"):GetPlayers()) do
player.Character:FindFirstChild("Humanoid").Health = 0
or if you’re looping through a model and all of it’s children you could do:
for partNumber, part in pairs(game.Workspace.Folder:GetChildren()) do
You could read this article for more information: Introduction to Scripting | Roblox Creator Documentation
oh so if i wanted to destroy a bunch of welds in a model I could use this. Ok I get it thanks.