Should I make a OnClientEvent to run Animations?

I’ve been loading and playing animations on the server.
Player presses a button > Fires to server > Plays a punch animation and damages etc.

But I’m wondering if I should do a OnClientEvent to play the animations or maybe preload the animations?

I was just going to load and play animations on the client based on the combo the player is on but I need it to align with the hitbox. Like if I use GetMarkerReachedSignal I need that on the server to spawn the hitbox and damage along with other stuff. So that’s going to be my last option.

Example Client Script
local Player = game:GetService("Players").LocalPlayer
local Char = Player.Character or Player.CharacterAdded
local Humanoid = Char.Humanoid

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")

local TriggerAnim = ReplicatedStorage.TriggerAnim

UserInputService.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	
	if input.KeyCode == Enum.KeyCode.E then
		TriggerAnim:FireServer()
	end
end)

TriggerAnim.OnClientEvent:Connect(function(AnimationToPlay)
	local Track = Humanoid.Animator:LoadAnimation(AnimationToPlay)
	Track:Play()
end)
Example Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TriggerAnim = ReplicatedStorage.TriggerAnim

TriggerAnim.OnServerEvent:Connect(function(player)
	TriggerAnim:FireClient(player, ReplicatedStorage:WaitForChild("LightAttack1"))
end)

No definitely not, it will take just as long for it to reach the player that pressed the button and extra long for all other players.

If you are looking for responsiveness, what you should do is play the animation on the client as soon as they press the button. Then send a message to the server and verify that they should damage the player. The server and other clients will get the animation since the character is network owned by the player.

4 Likes

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