I’m working on a small hangout with some simple emotes/animations that players can do. I have a LocalScript
that uses this code:
local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char
player.CharacterAdded:Connect(function(character)
char = character
end)
local currentAnim
local sit = false
uis.InputBegan:Connect(function(input,proc)
if not proc then
if input.KeyCode == Enum.KeyCode.B or input.KeyCode == Enum.KeyCode.DPadDown then
sit = not sit
if sit == true then
local humanoid = char:FindFirstChildOfClass("Humanoid")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://6571097367" --My sit animation
if humanoid then
local animator = humanoid:FindFirstChildOfClass("Animator")
if animator then
local animationTrack = animator:LoadAnimation(animation)
animationTrack:Play()
return animationTrack
else
animator = Instance.new("Animator", humanoid)
local animationTrack = animator:LoadAnimation(animation)
currentAnim = animationTrack
currentAnim:Play()
end
end
else
currentAnim:Stop()
end
end
end
end)
It throws the error: Players.A_thruZ.PlayerScripts.LocalScript:35: attempt to index nil with 'Stop'
. I don’t know if I’m just making some silly mistake. Help is appreciated.