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

Im having trouble playing a animation it has a error?

Asked by 3 years ago

Error: " 09:22:22.639 - ServerScriptService.Script:5: attempt to index nil with 'LoadAnimation'"

local uip = game:GetService("UserInputService")
local char = script.Parent
local human = char:WaitForChild("Humanoid", 1)
local anim = char:WaitForChild("Lookatwrist", 1)
local animtrack = human:LoadAnimation(anim)

uip.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then
        animtrack:Play()
        print("played")
    end
end)

i am trying to make it play a animation when you press e but it wont work please help

1
where is the script located? krowten024nabrU 463 — 3y
1
your timeout parameter on waitforchild might be the problem. It waited 1 second and then returned nil, because humanoid still wasnt found. I think thats what timeout does from what i saw Dfzoz 489 — 3y
0
nope cjkizzy286 40 — 3y
0
also the script is in server script service cjkizzy286 40 — 3y
View all comments (3 more)
0
wait so where should i set char cjkizzy286 40 — 3y
0
if it's in serverscriptservice then it's completely on the server and script.Parent will just return serverscriptservice Robowon1 323 — 3y
0
well what should i set char as cjkizzy286 40 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

You need to put this code into a LocalScript in StarterCharacterScripts or StarterPlayerScripts as UserInputService works only on the client.

You can then set:

char = game.Players.LocalPlayer.Character

Your char variable wasn't actually referencing a character, so there was no humanoid to load the script into as a result, causing the error.

Ad

Answer this question