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

why is the character variable a nil value?

Asked by
seikkatsu 110
5 years ago
local uis = game:GetService("UserInputService")
local anim = Instance.new("Animation")
local p = game.Players.LocalPlayer
local c = p.Character
local h = c:WaitForChild("Humanoid")
if h then
    print("H")
end

it doesn't print in the output h but it says that c is a nil value how can i solve this?

1 answer

Log in to vote
1
Answered by
Lazarix9 245 Moderation Voter
5 years ago
local c = p.Character or p.CharacterAdded:Wait()

local c = p.Character returned nil because character wasnt loaded, if you add or p.CharacterAdded:Wait() then if p.Character returns nil it will wait til character loads

0
thank you! seikkatsu 110 — 5y
0
welcome Lazarix9 245 — 5y
Ad

Answer this question