The animations doesn't work after reset

This is the current code:

local Player = game.Players.LocalPlayer
local tool = script.Parent
local Character = tool.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:FindFirstChild("Animator")
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://6350259222"
local AnimationTrack = Animator:LoadAniamtion(Anim)
local Anim2 = Instance.new("Animation")
Anim2.AnimationId = "rbxassetid://6364334315"
local AnimationTrack = Animator:LoadAnimation(Anim2)
local RS = game:GetService("ReplicatedStorage")
local Strengh = RS.RemoteEvents.Strengh
local db = false

--Animation
tool.Equipped:Connect(function()
	Anim:Play()
	Anim.Priority = Enum.AnimationPriority.Idle
	Humanoid.UseJumpPower = true
	Humanoid.WalkSpeed = 0
	Humanoid.JumpPower = 0
end)
tool.Activated:Connect(function()
	if db == false then
		db = true
		Anim2:Play()
		Anim2.Priority = Enum.AnimationPriority.Action
		Strengh:FireServer()
		wait(2)
		db = false
	end
end)
tool.Unequipped:Connect(function()
	Anim:Stop()
	Anim2:Stop()
	Anim:Destroy()
	Anim2:Destroy()
	Humanoid.UseJumpPower = true
	Humanoid.WalkSpeed = 16
	Humanoid.JumpPower = 50
end)

Is your game R6 or R15? R6 animations need R6 rigs and R15 needs R15 rigs.

My game will be on R15 platforms

1 Like
local Tool = script.Parent

local function Equipped()

	local Character = Tool.Parent

	if Character and Character:FindFirstChildOfClass("Humanoid") then

		local Humanoid = Character.Humanoid

		local Animator = Humanoid.Animator

		local Animation = Instance.new("Animation")

		Animation.AnimationId = "rbxassetid://6350259222" --Animation 1

		local AnimationTrack = Humanoid:LoadAnimation(Animation)

		AnimationTrack:Play()
	end
end

Tool.Equipped:Connect(Equipped)

local Debounce = true

local Animator = nil

local Humanoid = nil

local function Activated()

	if Debounce == true then

		Debounce = false

		local Character = Tool.Parent

		if Character and Character:FindFirstChildOfClass("Humanoid") then

			Humanoid = Character.Humanoid

			Animator = Humanoid.Animator

			local Animation = Instance.new("Animation")

			Animation.AnimationId = "rbxassetid://6364334315" --Animation 2

			local AnimationTrack = Humanoid:LoadAnimation(Animation)

			AnimationTrack:Play()
		end		

		local ReplicatedStorage = game:GetService("ReplicatedStorage")

		local StrengthEvent = ReplicatedStorage.RemoteEvents.Strength

		StrengthEvent:FireServer()

		wait(2)

		Debounce = true
	end
end

Tool.Activated:Connect(Activated)

local function Unequipped()

	if Animator then

		local PlayingAnimationTracks = Animator:GetPlayingAnimationTracks()		

		for _, PlayingAnimationTrack in pairs(PlayingAnimationTracks) do

			PlayingAnimationTrack:Stop()
		end
	end

	if Humanoid then

		Humanoid.UseJumpPower = true

		Humanoid.WalkSpeed = 16

		Humanoid.JumpPower = 50
	end
end

Instead of making the script local, make it server sided.

You can change the animation priority in the build-in animation editor plugin.

Please tell me if there are any issues.

Edit: You should not change anything in this script, if correct; everything should work for your setup.

should I pass the local script to a server script?

Yes. Remove the local script and insert a normal script.

There is another problem, if I put the code on the server, then I should no longer use FireServer ()

What exactly does your RemoteEvent do?

It causes that when I use the Activated event, the animation “Anim2” is played and force in the leaderstats

Please show me the code, animation 2 is played in the tool script I provided you. I could change it to do the stats too.

I think it should be changed because when I tried to use the code you gave me, it did not give me the error from before but the animations were not reproduced as they should:

local Player = game.Players.LocalPlayer
local tool = script.Parent
local Character = tool.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:FindFirstChild("Animator")
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://6350259222"
local AnimationTrack = Animator:LoadAniamtion(Anim)
local Anim2 = Instance.new("Animation")
Anim2.AnimationId = "rbxassetid://6364334315"
local AnimationTrack = Animator:LoadAnimation(Anim2)
local RS = game:GetService("ReplicatedStorage")
local Strengh = RS.RemoteEvents.Strengh
local db = false

--Animation
tool.Equipped:Connect(function()
	Anim:Play()
	Anim.Priority = Enum.AnimationPriority.Idle
	Humanoid.UseJumpPower = true
	Humanoid.WalkSpeed = 0
	Humanoid.JumpPower = 0
end)
tool.Activated:Connect(function()
	if db == false then
		db = true
		Anim2:Play()
		Anim2.Priority = Enum.AnimationPriority.Action
		Strengh:FireServer()
		wait(2)
		db = false
	end
end)
tool.Unequipped:Connect(function()
	Anim:Stop()
	Anim2:Stop()
	Anim:Destroy()
	Anim2:Destroy()
	Humanoid.UseJumpPower = true
	Humanoid.WalkSpeed = 16
	Humanoid.JumpPower = 50
end)

Did the animations not play or did they not play as intended?

This is the old code. I need the code that handles your RemoteEvent.

They reproduced but not as expected as some do not look or reproduce poorly

This is the code that is in a server script in ServerScriptService, it is a very simple but functional block of code:

local RS = game:GetService("ReplicatedStorage")
local Strengh = RS.RemoteEvents.Strengh

Strengh.OnServerEvent:Connect(function(player)
	player.leaderstats.Strengh.Value = player.leaderstats.Strengh.Value + 1
end)

I did not set the AnimationPriority, as you can set it while making the animation.

In fact, when I configure it in the script it gives me an error, but the animations do not play as they should.

This is how your script should look like:

local Tool = script.Parent

local function Equipped()

	local Character = Tool.Parent

	if Character and Character:FindFirstChildOfClass("Humanoid") then

		local Humanoid = Character.Humanoid

		local Animator = Humanoid.Animator

		local Animation = Instance.new("Animation")

		Animation.AnimationId = "rbxassetid://6350259222" --Animation 1

		local AnimationTrack = Humanoid:LoadAnimation(Animation)

		AnimationTrack:Play()
	end
end

Tool.Equipped:Connect(Equipped)

local Debounce = true

local Animator = nil

local Humanoid = nil

local function Activated()

	if Debounce == true then

		Debounce = false

		local Character = Tool.Parent

		if Character and Character:FindFirstChildOfClass("Humanoid") then

			Humanoid = Character.Humanoid

			Animator = Humanoid.Animator

			local Animation = Instance.new("Animation")

			Animation.AnimationId = "rbxassetid://6364334315" --Animation 2

			local AnimationTrack = Humanoid:LoadAnimation(Animation)

			AnimationTrack:Play()
		end		
		
		local Players = game:GetService("Players")
		
		local Player = Players:GetPlayerFromCharacter(Character)
		
		Player.leaderstats.Strength.Value += 1

		wait(2)

		Debounce = true
	end
end

Tool.Activated:Connect(Activated)

local function Unequipped()

	if Animator then

		local PlayingAnimationTracks = Animator:GetPlayingAnimationTracks()		

		for _, PlayingAnimationTrack in pairs(PlayingAnimationTracks) do

			PlayingAnimationTrack:Stop()
		end
	end

	if Humanoid then

		Humanoid.UseJumpPower = true

		Humanoid.WalkSpeed = 16

		Humanoid.JumpPower = 50
	end
end

For AnimationPriority:

As you can see, there is an option to change the animation priority in the build-in animation editor plugin.

The priorities are already set, but for greater security I also configure them through a script

There is no such ‘‘greater security’’ when talking about animations. In fact, it’s easier to just set the animation priority inside of the build-in plugin rather than setting them inside of scripts. And why would you set them both? Only one is necessary.