Error in getting character from player

  1. What do you want to achieve?
    To get the character of a player
  2. What is the issue?
    I’m using
    local player = game.Players:FindFirstChildOfClass(“Player”)
    print(player)
    local char = player.Character or player.CharacterAdded:Wait()
    But it ends up showing a error that it’s a nil value(player is not a nil value)
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have seen this code in many developer hub codes which means it should work

is this a local or server script?

It’s a server script. It’s for getting the character’s position.

Hey!

Simple alternative for the character is workspace[player.Name]. Let me know if that helps you!

Cheers

I’m have tried wait for child and find first child, but seems like it doesn’t work

do

for _,Player in pairs(game.Players:GetChildren()) do
     local character = workspace[Player.Name]
      if character then
          local pos = character.PrimaryPart.Position -- u can use cframe if ur also dealing with rotations
       end
end
1 Like

Ic thx a lot, I didn’t know about workspace[player.Name]

1 Like

Thx a lot, the problem has been fixed