Get Humanoid From Player

Hello. How do I get Humanoid From A Player with a server-side script? I have tried looking through the dev forums/hub and made many scripts but I still can’t get the Player’s Humanoid. How do I do it? (Humanoid is the Humanoid in the Player Model in workspace)

Any help is appriecated.

11 Likes

local Character = Player.Character
local Humanoid
if Character then
Humanoid = Character:FindFirstChild(“Humanoid”)
end

2 Likes
game.Players.ChildAdded:Connect(function(plr)
	while true do wait()
		if plr.Character then break end
	end
	local hum = plr.Character:WaitForChild("Humanoid")
end)
18 Likes

you can fire remote even to get humanoid

local remot = game.ReplicatedStorage.RemoteEvent
remot.OnServerEvent:Connect(function(plr)
	while true do wait()
		if plr.Character then break end
	end
	local hum = plr.Character:WaitForChild("Humanoid")
end)
1 Like

Another way to do it is

local playerService = game:GetService("Players")
playerService.PlayerAdded:Connect(function(plr)

@OP here’s the solution

local playerService = game:GetService("Players")
playerService.PlayerAdded:Connect(function(plr)
   local char = plr.Character or plr.CharacterAdded:Wait()
   local hum = char:WaitForChild("Humanoid")
   plr.CharacterAdded:Connect(function(char) --in case the player dies
      local hum = char:WaitForChild("Humanoid")
   end)
end)
4 Likes

Thanks. I will go try this out.

Thanks. I will go try this out

You can Simplify it even more :

game.Players.ChildAdded:Connect(function(player)
        player.CharacterAdded:Wait()--Wait Until The player is loaded
	    local humanoid = player.Character:WaitForChild("Humanoid")
        print(humanoid)
end)
4 Likes

You will need to use a CharacterAdded event, use RemoteEvents, but there is no way to get the Local Player < Character < Humanoid server sided, as it’s the Server and not the Client.

game.Players.PlayerAdded:Connect(function(player)
    local char = player.Character or player.CharacterAdded
    local hum = char:WaitForChild("Character")
end)
1 Like

You’ll need a PlayerAdded and CharacterAdded function in order to achieve this, depending on your case, here’s a PlayerAdded example:

local Players = game:GetService('Players')


local function PlayerAdded(Player)
	local function CharacterAdded(Character)
		local Humanoid = Character:FindFirstChildWhichIsA('Humanoid')
		if (Humanoid)
		then
			--
		end
	end
	
	local Character = Player.Character
	if (Character)
	then
		CharacterAdded(Character) -- If the character exists, run the CharacterAdded function.
	end
	Player.CharacterAdded:Connect(CharacterAdded) -- Listen for new characters to be added.
end


local GetPlayers = Players:GetPlayers()
for i = 1, (#GetPlayers)
do
	task.spawn(PlayerAdded, GetPlayers[i]) -- Run the function if the player(s) are already added (in parallel).
end
Players.PlyerAdded:Connect(PlayerAdded) -- Listen for new players.
1 Like