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 nil with 'WaitForChild'?

i tried making an animation command but it says this. what should i do now? here's the script:

local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local point = script.Animation
local Prefix = "!"
local point = hum:LoadAnimation(script.Animation)
player.Chatted:Connect(function(msg)
		if msg:Sub(1,6) == Prefix.."point" then
			point:Play()
		end 
	end) 

1 answer

✓ Accepted answer

The Character is nil. To get the character to not be nil you have to do this.

local player = game.Players.LocalPlayer
local char = player.Character
if not Character or not Character.Parent then
	Character = game.Players.LocalPlayer.CharacterAdded:Wait()
end
local hum = char:WaitForChild("Humanoid")
local point = script.Animation
local Prefix = "!"
local point = hum:LoadAnimation(script.Animation)
player.Chatted:Connect(function(msg)
        if msg:Sub(1,6) == Prefix.."point" then
            point:Play()
        end 
end) 

Hope this helps! :)

3 comments

0

To condense it down I'd reccomened doing just "local char = player.Character or player.CharacterAdded:Wait()".

0

It still says "attempt to index nill with waitforchild" but thanks for your help

0

Oh im sorry. I will try figuring out another solution!

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