What is the easiest why to get the caracter from player

ok so somtimes doing game.player.localplayer.Character does not work sometimes even on a server script like for example here’s this script writing and it dosent work:

script.parent.Mouse1Click:Connect(Function(player)
local animation = ReplicatedStorage.EmoteAnimation
local loadedAnimation = workspace[player.Name].Humanoid:LoadAnimation(animation)
end)

local Character = Player.Character or Player.CharacterAdded:Wait()
2 Likes

game.Players.LocalPlayer will never work on the server btw

You don’t need to complicate this line that much. You can just do local loadedAnimation = player.Character.Humanoid:LoadAnimation(animation) instead.

You can’t reference a LocalPlayer from a server-sided script, that is only do-able from a LocalScript. If you want to reference all of the players, you can use a for loop:

local players = game.Players:GetChildren()

for _,player in pairs(players) do
    local character = player.Character
    -- insert code here
end

it’s beneficiary to use this solution. Sometimes, when the player is added, the player will load before their character loads, so when you call for their character, it wont BE THERE. this overall is the best way to do it.

1 Like