Tool animations not playing client side but playing server side

The equipped, shooting, and reload animations for my gun tool are not playing client-side but are playing server side. I am currently using keyframes that I turn into animations to animate my characters, but the process of creating these animations is server-sided which I believe is causing this issue.

Is this the cause of the problem?

Just play the animation client-sided.

Send more information on how you’re currently playing the animations and I’ll be able to help you.

Here’s the scripts

Server Scripts

--Variables
local Tool = script.Parent
local Stuff = Tool:WaitForChild("Stuff")
local Data = Stuff:WaitForChild("Data")

local Can_Fire = Data.Can_Fire.Value
local Can_Reload = Data.Can_Reload.Value

-- Create animations from keyframes
local Keyframe_Hold = Stuff.pistol_hold
local Asset_Hold = game:GetService("KeyframeSequenceProvider"):RegisterKeyframeSequence(Keyframe_Hold)
local Animation_Hold = Instance.new("Animation")
Animation_Hold.Parent = Stuff
Animation_Hold.Name = "Pistol_Hold"
Animation_Hold.AnimationId = Asset_Hold

local Keyframe_Shoot = Stuff.pistol_shoot
local Asset_Shoot = game:GetService("KeyframeSequenceProvider"):RegisterKeyframeSequence(Keyframe_Shoot)
local Animation_Shoot = Instance.new("Animation")
Animation_Shoot.Parent = Stuff
Animation_Shoot.Name = "Pistol_Shoot"
Animation_Shoot.AnimationId = Asset_Shoot

local Keyframe_Reload = Stuff.pistol_reload
local Asset_Reload = game:GetService("KeyframeSequenceProvider"):RegisterKeyframeSequence(Keyframe_Reload)
local Animation_Reload = Instance.new("Animation")
Animation_Reload.Parent = Stuff
Animation_Reload.Name = "Pistol_Reload"
Animation_Reload.AnimationId = Asset_Reload


local function Gunshot(Sound)
	--gunshot code goes here, removed for readability
end





script.Parent.Fire.OnServerEvent:Connect(function(player, mousePosition)
	if Mag_Bullets > 0 then
		if Can_Fire == true then
			Can_Fire = false
			
			local Animation_Shoot = Stuff:FindFirstChild("Pistol_Shoot")
			local Anim_Track_Shoot = player.Character.Humanoid:LoadAnimation(Animation_Shoot)
			Anim_Track_Shoot:Play()
			Gunshot(Gunshot_Sound)
			Can_Fire = true
		end
	else
		Create_Sound(Empty_Sound)
	end
	

	
end)

script.Parent.Reload.OnServerEvent:Connect(function(player)
	local Anim_Track_Reload = player.Character.Humanoid:LoadAnimation(Animation_Reload)		
	script.Parent.UnEquipped.OnServerEvent:Connect(function()
		Anim_Track_Reload:Stop()
	end)
	Anim_Track_Reload:Play()
        wait(3)
	end
end)


Client Script:

local mouse = game.Players.LocalPlayer:GetMouse()
local UID = game:GetService("UserInputService")
local Tool = script.Parent
local Stuff = script.Parent:WaitForChild("Stuff")
local Equipped = false
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")



local Animation_Hold = Stuff:FindFirstChild("Pistol_Hold")
local Animation_Shoot = Stuff:FindFirstChild("Pistol_Shoot")
local Animation_Reload = Stuff:FindFirstChild("Pistol_Reload")

local Anim_Track_Hold = Humanoid:LoadAnimation(Animation_Hold)

-- Play animations when equipped, stop when dequipped

Tool.Equipped:Connect(function()
	Equipped = true
	Anim_Track_Hold:Play()
	
end)

Tool.Unequipped:Connect(function()
	Equipped = false
	Anim_Track_Hold:Stop()
	script.Parent.UnEquipped:FireServer()
end)

-- Player input functions below

UID.InputBegan:Connect(function(key, isTyping)
	if isTyping == false then
		if Equipped == true then
			if key.KeyCode == Enum.KeyCode.R then
				script.Parent.Reload:FireServer()
			end
		end
	end
end)



mouse.Button1Down:Connect(function()
	if Equipped then
		script.Parent.Fire:FireServer(mouse.Hit.p)
	end
end)

I removed a lot of unnecessary code for this issue, so things might appear weird. The server script creates the animations from keyframes, and plays the shooting and reload animations. This stuff is server sided because I need to check if the player has ammo to fire or reload, something I believe could be exploited if done client side. The client side script only gets player input and plays the equipped/stops the equipped animation.

Can’t reply for a while, I got to hit the gym.

Well yeah, you’re playing the shooting animation on the server-side. You’d want to play it on the client, when Mouse1 is down. You can still check the magazine etc on the client, just that if they we’re hacking an infinite magazine it’d appear to the player they are shooting, but in reality/server they aren’t.

Got it working, thanks for your help

1 Like

Great to hear, just mark it as solved if that’s all.