Sword Not Working on Activation

Hello! I’m currently trying to make a sword which damages humanoids on contact(using the touched event). I’m also using a remote event to send data from the client to the server. However, the sword doesn’t seem to do anything on activation. I don’t get any output errors and my debugging attempts failed to remedy the problem.

Local Script:

--Services
local Players = game:GetService("Players")

--Character Variables
local player = Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")

--Tool Instances
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local remote = tool:WaitForChild("RemoteEvent")

--Tool Data
local weaponWalkSpeed = 12
local debounce = false
local click = 0
local coolDown = 0.5

--Functions
local function loadAnims(animID, name)
	local anim = Instance.new("Animation", handle)
	anim.Name = name
	anim.AnimationId = "rbxassetid://" .. tostring(animID)
	local loadedAnim = animator:LoadAnimation(anim)
	return loadedAnim
end

--Animations
local idle = loadAnims(6870496366, "IdleAnim")
local attack1 = loadAnims(6872330609, "Attack1")
local attack2 = loadAnims(6872352230, "Attack2")
local attack3 = loadAnims(6872380254, "Attack3")

--Events
tool.Equipped:Connect(function()
	idle:Play()
	humanoid.WalkSpeed = weaponWalkSpeed
	remote:FireServer("Equipped")
end)

tool.Unequipped:Connect(function()
	idle:Stop()
	humanoid.WalkSpeed = 16
	remote:FireServer("Unequipped")
end)

tool.Activated:Connect(function(isTyping)
	if isTyping then return end
	if humanoid.Health == 0 then return end
	
	if debounce == false then
		debounce = true
	
		if click == 1 then
			attack1:Play()
		elseif click == 2 then
			attack2:Play()
		elseif click >= 3 then
			attack3:Play()
			click = 0 
		end
		remote:FireServer("Activated")
		wait(coolDown)
		debounce = false
	end
end)

Server Script:

--Services
local Players = game:GetService("Players")

--Tool Instances
local tool = script.Parent
local handle = tool.Handle
local hitBox = tool.Hitbox
local remote = tool.RemoteEvent

--Tool Data
local damage = 20

--Tool Sounds
local unsheatheSound = handle:FindFirstChild("Sword Unsheathe")
local slashSound = handle:FindFirstChild("Slash")
local slash2Sound = handle:FindFirstChild("Slash2")

--Functions
local function touch(hit, character)
	if hit.Parent == character then return end
	local hitHum = hit.Parent:FindFirstChild("Humanoid")
	
	if hitHum and hitHum.Health > 0 then
		hitHum:TakeDamage(damage)
	end
end

--Events
remote.OnServerEvent:Connect(function(player, event)
	if event == "Equipped" then
		unsheatheSound:Play()
	elseif event == "Unequipped" then
		unsheatheSound:Stop()
	elseif event == "Activated" then
		local character = tool.Parent
		hitBox.Touched:Connect(function()
			touch(character)
		end)
	end
end)

Any ideas on what’s wrong?

Are there any errors on the script?

No, I don’t get anything in the output

I’m seeing an area in your activated event, you set the click to 0 when it’s looking for 1, could this be the issue?

1 Like

Yeah, it works now… I feel so dumb. Thanks for noticing that!