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

Attempt to index nill with "WaitForChild"? (SOLVED)

So I am getting this error

Error:


10:44:05.690 - wait(1)
10:44:05.691 - ----Services----
10:44:05.692 - local ReplicatedStorage = game:GetService("ReplicatedStorage")
10:44:05.692 - local UserInputService = game:GetService("UserInputService")
10:44:05.694 -  (x2)
10:44:05.695 - ----Variables----
10:44:05.695 - 
10:44:05.696 - local player = game.Players.LocalPlayer
10:44:05.696 - local Char = player.Character
10:44:05.697 - local Mouse = p:12: attempt to index nil with 'WaitForChild'

Code which is erroring:

local RootPart = Char:WaitForChild("HumanoidRootPart")

Full Code:

wait(1)
----Services----
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")


----Variables----

local player = game.Players.LocalPlayer
local Char = player.Character
local Mouse = player:GetMouse()
local RootPart = Char:WaitForChild("HumanoidRootPart")


1 answer

✓ Accepted answer

your character probably didn't load in. So what you can do is:

wait(1)
----Services----
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")


----Variables----

local player = game.Players.LocalPlayer
local Char = player:WaitForChild("Character")
local Mouse = player:GetMouse()
local RootPart = Char:WaitForChild("HumanoidRootPart")

5 comments

0

also you dont need that wait(1)

0

Ok

0

Also I get an infinite yield how do I fix that?

0

if you get an infinite yield that means the character or the rootpart doesnt exist

0

what @DarkDanny04 said :)

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