I have reread the post a lot of times but I still dont understand how the solution given in the post works and I’m having trouble implementing it. Therefore, I would greatly appreciate it if somebody can elaborate how the solution works clearly and how to implement it.
Hook to every player’s character animator, when an animation is played: check if the animation is one set by the developer, and if it is, then stop and destroy it.
Here’s an example in StarterPlayerScripts that I was experimenting with:
local Players = game:GetService("Players")
local invalidAnimations = {
["http://www.roblox.com/asset/?id=507771019"] = true,
}
local function dereplicate(character)
character:WaitForChild("Humanoid").Animator.AnimationPlayed:Connect(function(track)
if invalidAnimations[track.Animation.AnimationId] then
track:Stop()
track:Destroy()
end
end)
end
for _, player in Players:GetPlayers() do
if player == Players.LocalPlayer then
continue
end
player.CharacterAdded:Connect(dereplicate)
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(dereplicate)
end)
Whenever the dance animation (http://www.roblox.com/asset/?id=507771019) is loaded to any non-local player’s character, the script immediately stops it.
if you mean only playing the animation on the enemy’s client, it defeats the purpose of what I’m trying to achieve. Here’s what my combat system currently looks like:
player hits the enemy on the client, play hit anims and vfx on enemy on the player’s client
→ fire remote event to server, perform sanity checks, if valid then apply damage and fire remote event to all clients except the player
→ play hit anims and vfx on enemy on all clients except the player
I’m trying to handle hit animations and vfx on the client for maximum responsiveness.
I think you’re failing to understand what I’m trying achieve… If hit anims are played on the server you will see a noticeable delay especially for players with high ping. Meanwhile, there’s little to no delay when it’s played on the player’s client, even with high ping.
Either you play it on the Enemy client and let them replicate it with a potential huge delay, or you play the Animation on the server with a smaller delay
Edit:
Using a remote event:
Client → Server → Client (The enemy client will replicate it afterwards again, causing the 2 Animation playbacks)
Playing the Animation on the Server:
Client → Server → Client (no second playback)
Playing the Animation on the Enemy Client for them to replicate it:
Client → Server → Client → Server → Client
This is the combat localscript:
User click event → create hitbox → check if enemy in hitbox → if valid then play vfx & hit anims on enemy and fire remote event to server.
Before firing any remote event, hit anims and vfx are played on the player’s client. If you’re still confused at this point please reread my post and the other post I’ve attached to above before replying.
Im understanding it perfectly well, im telling you that if you play the Hit animation on the Enemy, it will automatically replicate to everyone else so you just need to play the animation for the Enemy
Why not just hook my script to your RemoteEvent rather than CharacterAdded like I did?
Something like
LocalPlayer hits Player1, plays a client-side hit animation on Player1
LocalPlayer hooks to the validation RemoteEvent. When it receives a response, it will then connect to the server’s returned player (Player1) to stop their next animation (given that it’s the right one) on LocalPlayer’s client
Player1 receives the event, playing the hit animation locally, which replicates, but LocalPlayer stops it on their client.
The last step could also be done on the server for more guarantees, but if I understand correctly you aren’t doing that because an animation played on the client computes faster for that client.
The player hits someone and plays the Animation on the Enemy, the fired remote event will play the Animation for everyone else after doing sanity checks, the Enemy however will replicate the Animation to everyone else a second time because its played through a local script and the Player is the network owner of the character, which is why everyone except for the Enemy will see the Animation twice
Edit: If you are still confused about my answer then be more specific about which part you think I don’t understand.
Edit2: I re-read the topic, if you don’t want it to be replicated to everyone else by the Player a second time then play it on the server, it’s the same as using a RemoteEvent to play it basically, if you have a ping of below 100 there will be no visual delay.
I just tried that and the hit anim still didn’t play on the localplayer side like in the video above. I think the AnimationPlayed connection completely prevents the hit animation from playing which makes me even more confused about the answer given in the other post…
Can you debug which client is stopping which animation with breakpoints or print()? Ensure only the attacking client is stopping the attacked’s animation, and ensure that this only happens after the animation that the attacking client played on the attacked is finished.