Load Animation Requires an animation object

Hello, 2nd post today :sweat_smile:

Working on my gun system and I’m having a problem with my reload animation.

local player = game.Players.LocalPlayer

local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animation = script.Parent.Idle
local idletrack = humanoid:LoadAnimation(animation)
local reloadanim = script.Parent.Reload
local reloadtrack = humanoid:LoadAnimation(reloadanim)

local function equip()
	idletrack:Play()
end

local function unequip()
	idletrack:Stop()
	reloadtrack:Stop()
end
local canreload = true

local function reload(input, gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.R and canreload == true then
			reloadtrack:Play()
			canreload = false 
			script.Parent.Handle.reload.Ended:Wait()
			canreload = true
		end
	end
end
local usp = game:GetService("UserInputService")

usp.InputBegan:Connect(reload)



script.Parent.Equipped:Connect(equip)
script.Parent.Unequipped:Connect(unequip)

Thanks,

–Luke

Can I see the hierarchy of the objects in the explorer?

image

You should use animation controller instead for objects the syntax is the same

How would I do that? I’m not the best at scripting…

That’s why, it’s because there’s a Remote Event and Animation with the same name, it’s finding the Remote Event first. Try changing the name of the remote event to “ReloadRemote” or the animation to “ReloadAnim” and then re-referencing them in the script with their new name.

1 Like

Remove the humanoid and use a animation controller