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)
game.Players.ChildAdded:Connect(function(plr)
while true do wait()
if plr.Character then break end
end
local hum = plr.Character:WaitForChild("Humanoid")
end)
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)
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)
game.Players.ChildAdded:Connect(function(player)
player.CharacterAdded:Wait()--Wait Until The player is loaded
local humanoid = player.Character:WaitForChild("Humanoid")
print(humanoid)
end)
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)
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.