Changing an Animation ID in the animate script for a player causes bugged animations

  1. What do you want to achieve? I would like to change the idle, walk & run animation ID of the animate script of a player when they equip a tool, and then reset it back to normal when they unequip a tool.

  2. What is the issue? Works fine for the client, but other players see bugged animations.

  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub? I have looked through many forums however I have not found a solution.

Local Script:

-- [[ SERVICES ]] --
local Players = game:GetService("Players")
local RepStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")

-- [[ VARIABLES ]] --
local plr = Players.LocalPlayer
local backpack = plr:WaitForChild("Backpack")
local serverRemote = RepStorage:WaitForChild("Remotes"):WaitForChild("CutlassEquip")
local toolName = "Tool"
local ToolForEquipping = backpack:FindFirstChild(toolName)

UIS.InputBegan:Connect(function(input, gp)
	if gp then return end
	
	if input.KeyCode == Enum.KeyCode.E then
		if ToolForEquipping then
			serverRemote:FireServer(ToolForEquipping)
		end
	end
end)

Server Script:

-- [[ SERVICES ]] --
local RepStorage = game:GetService("ReplicatedStorage")

-- [[ VARIABLES ]] --
local serverEvent = RepStorage:WaitForChild("Remotes"):WaitForChild("CutlassEquip")
local humStateEvent = RepStorage:WaitForChild("Remotes"):WaitForChild("HumState")

local originalAnimations = {}

-- [[ EVENT ]] --
serverEvent.OnServerEvent:Connect(function(plr, ToolForEquipping)
	local backpack = plr:WaitForChild("Backpack")
	local chr = plr.Character or plr.CharacterAdded:Wait()
	local hum: Humanoid = chr:WaitForChild("Humanoid")
	local animate = chr:WaitForChild("Animate")
	
	local animateIdle: Animation = animate:WaitForChild("idle"):WaitForChild("Animation1")
	local animateWalk: Animation = animate:WaitForChild("walk"):WaitForChild("WalkAnim")
	local animateRun: Animation = animate:WaitForChild("run"):WaitForChild("RunAnim")

	if not originalAnimations[plr] then
		originalAnimations[plr] = {
			Idle = animateIdle.AnimationId,
			Walk = animateWalk.AnimationId,
			Run = animateRun.AnimationId
		}
	end

	local animationsFolder = RepStorage:WaitForChild("Animations")
	local cutlassIdle = animationsFolder:WaitForChild("CutlassIdle")
	local cutlassWalk = animationsFolder:WaitForChild("CutlassWalk")
	
	if ToolForEquipping.Parent == backpack then
		hum:EquipTool(ToolForEquipping)
		task.wait()
		humStateEvent:FireClient(plr, Enum.HumanoidStateType.Freefall)
		animateIdle.AnimationId = cutlassIdle.AnimationId
		animateWalk.AnimationId = cutlassWalk.AnimationId
		animateRun.AnimationId = cutlassWalk.AnimationId
		task.wait(0.5)
		humStateEvent:FireClient(plr, Enum.HumanoidStateType.Running)

	elseif ToolForEquipping.Parent == chr then
		hum:UnequipTools()
		task.wait()
		humStateEvent:FireClient(plr, Enum.HumanoidStateType.Freefall)
		animateIdle.AnimationId = originalAnimations[plr].Idle
		animateWalk.AnimationId = originalAnimations[plr].Walk
		animateRun.AnimationId = originalAnimations[plr].Run
		task.wait(0.5)
		humStateEvent:FireClient(plr, Enum.HumanoidStateType.Running)
	end
end)

Bug:

2 Likes

Try using animation on client-side script

usually this is replication, althought you see the model is being owned on NetworkOwnerShip Client

which means client sends data and server gets data and sends data

the best use is using animations on client-script

for NPCS use server-side, althought you could just make play NPC’s animation on client while on server-side NPC is Position default of mesh

The animation isn’t being played via the server script, only the animation ID that is stored in the animate script is being changed.

well, did you tried change animationid on client ?

i mean try it and see results

I tried it & it doesn’t change anything. The bug is still there.

Update: Could be that you can’t change it this way.

How did you end up changing it?

By playing the idle animation on a local script & stopping the idle animation then playing the run animation when the .Running event fires. I simply made a custom basic movement system, however you can try and use this solution:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.