Animation not loading when playing

Hey there!
I’m scripting a combat system for a game I am a developer for but I am having some problems with the tools animation, it doesn’t use the idle that is already saved “Idle_Animation”.

Here’s the code

 tool.Equipped:Connect(function()
	if canIdle then
		canIdle = true
	end
	local str = Instance.new("StringValue")
	str.Name = "Idle_Animation"
	str.Value = "Idle_Animation" 
	str.Parent = tool
	canIdle = true
	Sounds.Unsheath:Play()
end)

I think it is working it’s just not staying the whole time.
If you need to see more just let me know and I can show you.

3 Likes

So is there already an animation instance inside of the tool or not? Also, what is the StringValue for; to name the animation?

1 Like

Yes, and yes. How do I make it permanently play the animation though?

1 Like

An answer and also a note:

You have to either:

  1. Load the animation, set it to loop, then re-export it.

  2. Inside of the script, define the Animation instance and put a line of script on it’s own saying [AnimationInstance].Looped = true.

You don’t have to use a StringValue to change the animation’s name. You can change it directly within your script or change the name of it in it’s properties.

Unless I’ve mistaken that part of the code.

1 Like

Unfortunately, I do not have the original copy of the animations as I am just a programmer hired to work on the combat system.

The string just accesses the default “Slash” so it’s not just hovering.

You can still loop the animation by defining the Animation Instance and doing .Looped = true. Also, you’ve actually answered your question there. You cannot see animations if they weren’t made by you and wasn’t uploaded in a group that you both share.

You have to own the animation to be able to play it. Is it a group game? If so, they should upload the animations in the group.

Okay they are getting me the files now.

Okay I’ve taken some time to fix the code, though it still isn’t playing the animations, I think my mistakes are just silly mistakes that I’ve missed.

local tool = script.Parent
local canDamage = false
local canSwing = true
local canIdle = true
local Attack1_Animation = tool.Animations.Attack1_Animation
local Idle_Animation = tool.Animations.Idle_Animation
local Handle = script.Parent:WaitForChild(("Handle"))
local AttackTrail = tool.Handle.AttackTrail


local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local Animator = humanoid:WaitForChild("Animator")

local Sword_Walk_Animation = Instance.new("Animation")
Sword_Walk_Animation.AnimationId = "rbxassetid://9404399317"
local Sword_Walk_AnimationTrack = Animator:LoadAnimation(Sword_Walk_Animation)
Sword_Walk_AnimationTrack.Priority = Enum.AnimationPriority.Movement
Sword_Walk_AnimationTrack.Looped = true

local Sword_Slash_Animation = Instance.new("Animation")
Sword_Slash_Animation.AnimationId = "rbxassetid://9404404634"
local Sword_Slash_AnimationTrack = Animator:LoadAnimation(Sword_Walk_Animation)
Sword_Slash_Animation.Priority = Enum.AnimationPriority.Action
Sword_Slash_Animation.Looped = false

DamageValues = {
	Attack1 = 5,
	Attack2 = 10,
	Attack3 = 30
}    

Effects = {
	BloodEmitter = Handle:WaitForChild("BloodEmitter"),
}

Sounds = {
	Slash = Handle:WaitForChild("SlashSound"),
	Lunge = Handle:WaitForChild("LungeSound"),
	Unsheath = Handle:WaitForChild("EquipSound"),
	HitSound1 = Handle:WaitForChild("HitSound1")
}


tool.Equipped:Connect(function(player)
	Sword_Walk_AnimationTrack:Play()
	Sounds.Unsheath:Play()
end)

local function onTouch(otherPart)

	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")

	if not humanoid then 
		return 
	end

	if humanoid.Parent ~= tool.Parent and canDamage then 
		humanoid:TakeDamage(5)
		Sounds.HitSound1:Play()
	else
		return
	end
	canDamage = false
end

local function slash()
	if canSwing then
		canSwing = false
		Sword_Slash_AnimationTrack:Play()
		canDamage = true
		wait(1)
		canSwing = true
		Sword_Slash_AnimationTrack:Play()
	end
end

tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)


tool.Activated:Connect(slash)

tool.Handle.Touched:Connect(onTouch)

^ This is the full code but just pick out the parts where it uses :Play()

Is the animations owned by you, like were you the one who exported the animations?

No, I do not own them. I had the owner give me all the ids though. Which is what I used in the code.

That’s the reason it’s not loading. Nothing is wrong with your script, you’ll need the owner to test the game out for you to see if the animations work.

Unless the game has been published in a group that you both share and the animations has been under that group as well, the animations won’t show for the person who wasn’t the one uploading the animation.

1 Like