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

Im having trouble playing a animation it has a error?

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

7 comments

1

where is the script located?

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

0

nope

0

also the script is in server script service

0

wait so where should i set char

0

if it's in serverscriptservice then it's completely on the server and script.Parent will just return serverscriptservice

0

well what should i set char as

1 answer

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.

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