I need help with my animation script its a keybind one. When I press J the first time everything works but if I try again it says "LoadAnimation requires an Animation object", and it says the error is on line 15. Here is my script:
local UIS = game:GetService('UserInputService') local plr = game.Players.LocalPlayer local Char = plr.Character or plr.CharacterAdded:Wait() local Key = 'J' local Animation = Instance.new('Animation') Animation.AnimationId = 'rbxassetid://4594975382' UIS.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end local KeyPressed = Input.KeyCode if KeyPressed == Enum.KeyCode[Key] then print(plr.Name..' has pressed'..Key) local Load Animation = Char.Humanoid:LoadAnimation(Animation) Load = Animation:Play() end end)
Try this,
local UIS = game:GetService('UserInputService') local plr = game.Players.LocalPlayer local Char = plr.Character or plr.CharacterAdded:Wait() local Key = 'J' local Animation = Instance.new('Animation') Animation.AnimationId = 'rbxassetid://4594975382' UIS.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end local KeyPressed = Input.KeyCode if KeyPressed == Enum.KeyCode[Key] then print(plr.Name..' has pressed'..Key) local Animation = Char.Humanoid:LoadAnimation(Animation) Animation:Play() end end)
I changed these lines from this:
local Load Animation = Char.Humanoid:LoadAnimation(Animation) Load = Animation:Play()
To this:
local Animation = Char.Humanoid:LoadAnimation(Animation) Animation:Play()
You can't have spaces in variables and there's no need to set Load = Animation:Play() that does nothing. Animation refers to the loaded animation inside the character and you simply play the animation.