I'm working on a fighting system, but it's not working

I’ve got a tool in replicated storage called “Combat” there is a script that adds it to the player’s backpack.

Screenshot 2025-04-06 135657
Ignore the dummies script.

I have two scripts a client and a server script
the server script is in control of the damage
Screenshot 2025-04-06 135526
The client is in control of the animations
Screenshot 2025-04-06 135451


the character on the left is doing the attack animation and the character on the right is going the idle/blocking animation

My issue is that the scripts just aren’t working, and I don’t know why

Client

-- LocalScript inside StarterCharacterScripts

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local tool = player.Backpack:WaitForChild("Combat") -- The tool in the player's backpack
local mouse = player:GetMouse()
local humanoid = character:WaitForChild("Humanoid")
local attackAnim = tool:WaitForChild("attack")  -- The attack animation in the tool
local idleAnim = tool:WaitForChild("idle") -- The idle animation in the tool

local canAttack = true
local attackCooldown = 1 -- 1 second cooldown for attacks
local punchDamage = 5
local kickDamage = 10

-- Function to perform attack animation and send damage to the server
local function performAttack()
	if canAttack then
		canAttack = false

		-- Play the attack animation
		local animTrack = humanoid:LoadAnimation(attackAnim)
		animTrack:Play()

		-- Fire damage events at the right time using keyframes
		animTrack.KeyframeReached:Connect(function(keyframeName)
			if keyframeName == "RightPunch" then
				-- Right Punch
				game.ReplicatedStorage:WaitForChild("CombatEvent"):FireServer(mouse.Target, punchDamage)
			elseif keyframeName == "LeftPunch" then
				-- Left Punch
				game.ReplicatedStorage:WaitForChild("CombatEvent"):FireServer(mouse.Target, punchDamage)
			elseif keyframeName == "Kick" then
				-- Kick
				game.ReplicatedStorage:WaitForChild("CombatEvent"):FireServer(mouse.Target, kickDamage)
			end
		end)

		-- Set cooldown for the attack
		wait(attackCooldown)
		canAttack = true
	end
end

-- Handle the tool equipped event
tool.Equipped:Connect(function()
	local idleAnimTrack = humanoid:LoadAnimation(idleAnim)
	idleAnimTrack:Play()
end)

tool.Activated:Connect(function()
	performAttack()
end)

Server

-- Script: Inside ServerScriptService

local combatEvent = game.ReplicatedStorage:WaitForChild("CombatEvent")

combatEvent.OnServerEvent:Connect(function(player, target, damage)
	if target and target.Parent and target.Parent:FindFirstChild("Humanoid") then
		local humanoid = target.Parent:FindFirstChild("Humanoid")
		if humanoid then
			humanoid:TakeDamage(damage)
		end
	end
end)

Does your tool have a handle?

If not, turn off RequiresHandle in the Properties panel for the tool:

Screen Shot 2025-04-06 at 6.11.16 PM

2 Likes

the tool is nothing it just has no handle

are you kidding me, bro that’s all I had to do

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