You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
i want to get the humanoid of all the players in the server
-
What is the issue? Include screenshots / videos if possible!
i just made code and im wondering why it doesnt work
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
my code:
local player = game:WaitForChild(“Players”)
if player then
local character = player:WaitForChild(“Character”)
local humanoid = character:FindFirstChild(“Humanoid”)
end
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- This is an example Lua code block
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
The reason is because you are not getting the children of players.
All you are doing is trying to get the humanoid of the game.players
1 Like
wait(5)
for i,v in pairs(game.Players:GetChildren()) do
v.Character.Humanoid.Health = 0
end
Thats how you would get everyone’s humanoid
2 Likes
local table = {}
for i, v in pairs (game.Player:GetChildren()) do
table.insert(table, i, workspace[v].Humanoid)
end
is this code for a local script or for the server?
because i want it from the server btw
That should work in the server script yes as that is where all of the players are stored as such on the server not locally.
Character might not be loaded and that is the case most of the time.
It is always better to wait for the character if it is not loaded.
`
local Character = Player.Character or Player.CharacterAdded:Wait()
`
I agree with you. You can also detect when the character is (re)spawned. I believe player.CharacterAdded:Wait(): is mostly used in LocalScripts, not server scripts.
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
end)
end)