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

Error: attempt to index local 'Character' (a nil value)?

What does this mean and how can I fix this? It's a localscript and here's the code:

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Torso = Character.Torso --Error seems to be here

Thanks for helping me out!

3 comments

0

it means that the player currently has no character. you just need to wait until they have spawned.

0

Add this after local player part. repeat wait until Player:FindFirstChild("Character")

0

@iRexBot, Character isn't a child of Player, it's a Property: http://wiki.roblox.com/index.php?title=API:Class/Player/Character

1 answer

You must wait for the character to spawn before you can do anything to it.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Torso = Character:WaitForChild("Torso") --if R15 use UpperTorso, LowerTorso or HumanoidRootPart instead

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