Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
ali7682 17
6 years ago

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!

0
it means that the player currently has no character. you just need to wait until they have spawned. User#5423 17 — 6y
0
Add this after local player part. repeat wait until Player:FindFirstChild("Character") iRexBot 147 — 6y
0
@iRexBot, Character isn't a child of Player, it's a Property: http://wiki.roblox.com/index.php?title=API:Class/Player/Character thesit123 509 — 6y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

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
Ad

Answer this question