Cannot adjust speed of custom player animations with the server

I want to change the speed of certain animations I made for the player depending on the tool that they have equipped, and I want to do it in a server script. I don’t want to do it in a local script because I fear that it is easily exploitable.

It works like this:

  • A server script is used to make a remote event that uses a parameter that specifies the animation that is played and changes the speed depending on what weapon is equipped (another parameter)
  • A local script fires this remote event with the parameters that are needed.

The problem is that, when this is executed, the server script throws an error that says the animationtrack parameter is nil, even though it isn’t nil on the client.

I’ve eventually noticed that all player animations when replicated to the server aren’t assigned their previous names and that they are all just named “Animation”.

With this in mind, is there any way I could change the speed of the animations in the server, or in a manner that isn’t exploitable?

Below isn’t all of my code, but only the parts that I think are part of the problem or could be used to solve it.

--Server Script
Attack.OnServerEvent:Connect(function(player, weapon:string, animTrack:AnimationTrack) 
	animTrack:AdjustSpeed(WeaponData[weapon].Speed)
end)

--Local Script
local ChosenAnim

for _, anim in pairs(AttackAnims) do
	if anim:GetAttribute("AnimationNumber") == AnimCount then
		ChosenAnim = Animator:LoadAnimation(anim)
	end 
end

ChosenAnim:Play()

ChosenAnim:GetMarkerReachedSignal("AttackStart"):Connect(function()
	AttackEvent:FireServer(Weapon.Name, ChosenAnim)
	print(ChosenAnim)
end)

--Module Script (Not too important. Just holds some values I need.)
Weapons["Fists"] = {
	["Speed"] = 1,
	},
}

Weapons["Boxing Gloves"] = {
	["Speed"] = 1.25,
	},
}

The exact error I’m getting is: ServerScriptService.WeaponScripts.AttackServer:31: attempt to index nil with ‘AdjustSpeed’

2 Likes

As defined in the documentation of AnimationTrack, the Speed property is not Replicated to the Server. On top of that if it were to be replicated to the server simply changing the value of Speed would not work as the Server and the Client store different Instances of the same object (with the exception to this being when transfering Instances from Server to Client, NOT CLIENT TO SERVER). To get around this you can either make your AttackEvent a Remote Function that returns the desired speed of the animation, and set it on the client. Or you can say AttackEvent:FireClient(player, speed) on the Server and receive it on the client and set the speed there.

1 Like

Thanks! The remote function solution worked. I never really paid much attention to the side descriptions besides deprecated lol

1 Like

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