So in my combat system, it seems to play the animation for everyone. only the animation. not the hitbox initiation. The combat system detects if I left click in the local script and the server script handles damage and animations:
ServerScript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("AnimationEvent")
local damageEvent = ReplicatedStorage:WaitForChild("DamageEvent")
local KnockBackConstructorModule = require(ReplicatedStorage:WaitForChild("Knockback_Module"))
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local animations = {
script:WaitForChild("Animation1"),
script:WaitForChild("Animation2"),
script:WaitForChild("Animation3"),
script:WaitForChild("Animation4")
}
local currentAnimation = 1
local debounce = false
local cooldownActive = false
local lastActionTime = tick()
local animationTracks = {}
for i, anim in ipairs(animations) do
animationTracks[i] = humanoid:LoadAnimation(anim)
end
local function playCurrentAnimation(player)
if debounce then return end
debounce = true
local currentTime = tick()
if currentTime - lastActionTime > 1 then
currentAnimation = 1
end
lastActionTime = currentTime
local track = animationTracks[currentAnimation]
if track then
track:Play()
remoteEvent:FireClient(player, track.Length, currentAnimation)
track.Stopped:Wait()
end
currentAnimation = currentAnimation % #animations + 1
if currentAnimation == 1 then
cooldownActive = true
wait(2)
cooldownActive = false
end
debounce = false
end
remoteEvent.OnServerEvent:Connect(function(player)
if not cooldownActive then
playCurrentAnimation(player)
end
end)
damageEvent.OnServerEvent:Connect(function(player, hit, humanoid, currentAnimation)
if humanoid and humanoid:IsA("Humanoid") then
humanoid:TakeDamage(5)
local enemyCharacter = humanoid.Parent
local knockbackRange = 2.5
local knockbackHeight = 1.5
if currentAnimation == 4 then
knockbackRange = 8.0
knockbackHeight = 30.0
end
local knockbackConstructor = KnockBackConstructorModule.new(enemyCharacter, character, knockbackRange, knockbackHeight)
knockbackConstructor:Construct()
end
end)
LocalScript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local remoteEvent = ReplicatedStorage:WaitForChild("AnimationEvent")
local damageEvent = ReplicatedStorage:WaitForChild("DamageEvent")
local RaycastHitbox = require(ReplicatedStorage:WaitForChild("RaycastHitboxV4"))
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {character}
Params.FilterType = Enum.RaycastFilterType.Exclude
local newHitbox = RaycastHitbox.new(character)
newHitbox.RaycastParams = Params
newHitbox.Visualizer = true
newHitbox:SetPoints(character:FindFirstChild("Left Arm"), {Vector3.new(0, 0, 0), Vector3.new(0.5, 0, 0), Vector3.new(-0.5, 0, 0), Vector3.new(0,0.5,0), Vector3.new(0,-0.5,0)})
newHitbox:SetPoints(character:FindFirstChild("Right Arm"), {Vector3.new(0, 0, 0), Vector3.new(0.5, 0, 0), Vector3.new(-0.5, 0, 0), Vector3.new(0,0.5,0), Vector3.new(0,-0.5,0)})
newHitbox.OnHit:Connect(function(hit, humanoid)
print(hit)
damageEvent:FireServer(hit, humanoid, newHitbox.currentAnimation)
end)
local debounce = false
local function startHitbox(duration, animationNumber)
if debounce then return end
debounce = true
newHitbox.currentAnimation = animationNumber
newHitbox:HitStart()
wait(duration)
newHitbox:HitStop()
debounce = false
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 and not gameProcessed then
remoteEvent:FireServer()
end
end)
remoteEvent.OnClientEvent:Connect(function(animationLength, animationNumber)
startHitbox(animationLength, animationNumber)
end)