Am unable to get character from player, really frustrating

The title explains it all. Here’s my code:

local players = game:GetService("Players")
local player = players.LocalPlayer
print(player.Name)
local character = player.Character
print(character)

Here’s the output:
Screenshot 2024-07-25 at 11.28.34 AM
What did I do wrong?

2 Likes

Try replacing

local character = player.Character

With

local character = player.Character or player.CharacterAdded:Wait()
1 Like

Probably because the script loads faster than the player’s character

Here’s the solution as mentioned above:

local character = player.Character or player.CharacterAdded:Wait()

The “or” basically checks if the first thing you are looking for is nil or not. So in this case the script loads faster than the character resulting in the first attempt being nil, so it goes to the second part and waits for the character.

lmk if this helped. GL!

Thank you! What I can assume happened is that the character didnt load in time! :slight_smile:

Yep.

type or paste code here

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.