Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can't get the Character of a Player?

I have a tool in starterpack and inside there a server script. My idea was to get the player from the backpack and then the character, but it errors saying nil or that it's not a valid member of DataModel. I found the player, but I can't use Player.CharacterAdded:Wait() or Player.Character for some reason.

local tool = script.Parent
local player = script:FindFirstAncestorWhichIsA("Player")
local character = player.Character or player.CharacterAdded:Wait()

5 comments

1

The problem is because player is nil. I need more details from you to give you a solution.

0

bro I literally said I found the player and it's "FindFirstAncestorWhichIsA("Player")"

0

Try print(type(character)) and see what is printed

0

Sindro, you grabbed the player wrong.

0

ight how do I grab it right

2 answers

both player and character print right, but if I try to parent a model FROM the tool to the character it breaks saying "attempt to index nil with character"

(tool variable is the model)

local tool = script.Parent
local player = script:FindFirstAncestorWhichIsA("Player")
local character = player.Character or player.CharacterAdded:Wait()
print(player)
print(character)
tool.Parent = character

prints but immediately after it says nil so...

local tool = script.Parent
local player = script:FindFirstAncestorWhichIsA("Player")
local character = game.Workspace:FindFirstChild(player.Name)

This discussion is preserved as it was. New answers, comments, and votes are closed.