Help with Equipping Animations

| I N T R O D U C T I O N |

This will probaly be like 1 of the last times I ask for help when Scripting.
but um, I am making this Animation shop the only problem is when the player tries to equip it
the animation dosnt show up or work, its still the default animation. i tried parenting it to the character it didnt work, i tried doing startercharacter and it didnt work any way i can fix this?

| S C R I P T |

game.Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
	
	local PlayersAnims = Instance.new("Folder", Player)
	PlayersAnims.Name = "PlayersAnims"
	
	local SC = Instance.new("NumberValue", leaderstats)
	SC.Name = "SpeedCoinz"
	SC.Value = 10000
	
	local OwnsScoutFlyerAnim = Instance.new("BoolValue", PlayersAnims)
	OwnsScoutFlyerAnim.Name = "ScoutFlyerAnim"
	OwnsScoutFlyerAnim.Value = false
	
	game.ReplicatedStorage.RemoteEvents.BuyScoutFlyerAnim.OnServerEvent:Connect(function(plr)
		plr.leaderstats.SpeedCoinz.Value -= 750
		plr.PlayersAnims.ScoutFlyerAnim.Value = true
		print("Player Now Owns Scout Flyer")
	end)
	
	game.ReplicatedStorage.RemoteEvents.EquipScoutFlyerAnim.OnServerEvent:Connect(function(plr)
		local char = plr.Character
		local customanim = game.ServerStorage.PlayerAnimations.ScoutFlyer.Animate
		plr:LoadCharacter()
		local CurrentCharAnim = char:FindFirstChild("Animate")
		wait()
		CurrentCharAnim:Destroy()
		wait()
		if not char:FindFirstChild("IsCustom") then
			local newAnim = customanim:Clone()
			newAnim.Parent = char
		end
	end)
end)
1 Like

To play an animation:

local loadedanim = char.Humanoid.Animator:LoadAnimation(customanim)
loadedanim:Play()

Also, to remove animations do:

local playinganims = char.Humanoid.Animator:GetPlayingAnimationTracks()
for i, anim in pairs(playinganims) do
    if anim and anim.Name == "Animate" then
        anim:Stop()
    end
end

Please list this as Solution, thanks!

dang, i keep forgetting about loadanim when scripting i cant remember crap.
but ill try using this tho

wait will this work with the script itself like
its a custom walk, run, jump etc animation itself does it still work like that?
im still learning about animations

Yes, if you set the anim priority. For example, Action would work.

all of their anim priorities are set to default.

Oh… well, I think you can set animation priority directly from a script.
I would suggest setting it to Action, the highest.

animationtrack.Priority = Enum.AnimationPriority.Action

like its a animation Script.
for example if i tested the game i would go inside the player
and take the animation script, so thats what i have and i edit the animation id
and etc. just to make this clear

i also got this error saying load anim requires a animation or something

game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new(“Folder”, Player)
leaderstats.Name = “leaderstats”

local PlayersAnims = Instance.new("Folder", Player)
PlayersAnims.Name = "PlayersAnims"

local SC = Instance.new("NumberValue", leaderstats)
SC.Name = "SpeedCoinz"
SC.Value = 10000

local OwnsScoutFlyerAnim = Instance.new("BoolValue", PlayersAnims)
OwnsScoutFlyerAnim.Name = "ScoutFlyerAnim"
OwnsScoutFlyerAnim.Value = false

game.ReplicatedStorage.RemoteEvents.BuyScoutFlyerAnim.OnServerEvent:Connect(function(plr)
	plr.leaderstats.SpeedCoinz.Value -= 750
	plr.PlayersAnims.ScoutFlyerAnim.Value = true
	print("Player Now Owns Scout Flyer")
end)

game.ReplicatedStorage.RemoteEvents.EquipScoutFlyerAnim.OnServerEvent:Connect(function(plr)
	local char = plr.Character
	local customanim = game.ServerStorage.PlayerAnimations.ScoutFlyer.Animate
	plr:LoadCharacter()
	local playinganims = char.Humanoid.Animator:GetPlayingAnimationTracks()
	for i, anim in pairs(playinganims) do
		if anim and anim.Name == "Animate" then
			anim:Stop()
		end
	end
	wait()
	if not char:FindFirstChild("IsCustom") then
		local loadedanim = char.Humanoid.Animator:LoadAnimation(customanim)
		loadedanim:Play()
	end
end)

end)

Use WaitForChild(), otherwise the anim may not load in before you check for it. So:

local customanim = game.ServerStorage:WaitForChild("PlayerAnimations"):WaitForChild("ScoutFlyer"):WaitForChild("Animate")

Also, you should set the priority of loadedanim.

loadedanim.Priority = Enum.AnimationPriority.Action

i really dont think i could do this sorry.
i shouldnt of went with something this big but ill try explaining this a lil more
the animation is a script with all animation id’s inside the script’s code
and animation id’s inside the script itself
the animation ids are inside IntValues which are inside the Script.
also im still getting a error it couldnt find the anim or anything theres just nothing we can do.
i have to make something else.
but rn ima just take a break from developing.

I learnt more scripting today and I found the solution to the problem myself!
and i did something diffrent with the scripting.