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

attempt to index nil with 'WaitForChild'?

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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! :)

0
To condense it down I'd reccomened doing just "local char = player.Character or player.CharacterAdded:Wait()". Benbebop 1049 — 3y
0
It still says "attempt to index nill with waitforchild" but thanks for your help dante_dalmatian 9 — 3y
0
Oh im sorry. I will try figuring out another solution! MarcTheRubixQb 153 — 3y
Ad

Answer this question