Animation not canceling from another event

Hello, I’m trying to make a weapon system in my game but when the animation is loaded in one event. With the other event that can’t stop the other loaded animation. Can someone help?


HoldTrack.AnimationId = "6887187273"

local Hold = player.Character.Humanoid:LoadAnimation(HoldTrack)

game.ReplicatedStorage.Events.StartAnim.OnClientEvent:Connect(function()
	local Weapon = nil
	for i,weapon in pairs(player.Character:GetChildren()) do
		if weapon:IsA("Model") then
			
			for i,v in pairs(game.ReplicatedStorage.Weapons:GetChildren()) do
				if v.Name == weapon.Name then
					Weapon = v
					
					
					
					HoldTrack.AnimationId = Guns.GunInfo[Weapon.Name]["Hold"]
					local Hold = player.Character.Humanoid:LoadAnimation(HoldTrack)
					
					print(HoldTrack.AnimationId )
					Hold:Play()
				end
			end
		end
	end
end)

game.ReplicatedStorage.Events.StopAnim.OnClientEvent:Connect(function()
	print(HoldTrack.AnimationId )
	Hold:Stop()
end)
1 Like

You never placed a local infront of the Hold
track part.

do this btw
HoldTrack.AnimationId = "rbxassetid://6887187273"

It seems like you’re assigning 2 variables with the name “Hold” in 2 separate scopes. If you assign a variable something and then want to change it later you will need to call the name of the variable without “local” in front of it. If you don’t this will create a new variable instead of changing the old one.

local Number = 2

something.Touched:Connect(function()

       local Number = 5
       print(Number) -- 5
end)

print(Number) -- 2

To fix your issue since you already loaded the animation at the top of the script

local Hold = player.Character.Humanoid:LoadAnimation(HoldTrack)

you can get rid of this line inside of the .OnClientEvent event.

local Hold = player.Character.Humanoid:LoadAnimation(HoldTrack)

and keep the

Hold:Play()
2 Likes

Found a issue or I did it wrong where when you delete it, it will play the default animation
HoldTrack.AnimationId = “rbxassetid://6887187273”

it just plays this and nothing else

i put the load because you need to load its new animation

Isn’t that the animation that you want to play? You’re only telling the script to play the “Hold” animation

the default is there so the other OnClientEvents know what hold is so that they can have a variable because in my game all the weapons have a hold animation we want the specific animation to play for that weapon, so when you pull out the Bat the only animation played is the default first animation because there is no update to the animation

??? local where :confused: ???

try using;

local HoldTrack = --location
HoldTrack.AnimationId = rbxassetid://6887187273

wait(.5)

local AnimId = HoldTrack.AnimationId