I’m making a sword and I’m using the .touched function as the hitbox. But there is a bug within the sword that stacks the hits of the sword and when it touches another rig/player all of those stacked hits register.
It’s hard to explain but hopefully this should be clear.
I’ve tried making a different styled hitbox (like raycasting) but it got too complicated and messy that I just resorted back to .touched
Here is the code to my hitbox
local function Hitbox()
local Sword = Tool.Handle
local Character = Tool.Parent
local plr = game.Players:GetPlayerFromCharacter(Tool.Parent)
local HasHit = false
Sword.Touched:Connect(function(hit)
if HasHit == false then
if hit.Parent == Character then -- To avoid damaging the player wielding the sword
return
else
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
Humanoid:TakeDamage(5)
HasHit = true
GiveHits(Character)
local SoundsFolder = script.Parent.Sounds:GetChildren()
local Sound = SoundsFolder[math.random(1, #SoundsFolder)]
Sound:Play()
end
end
end
end)
end
EventsFolder.ClientToServer.OnServerEvent:Connect(function(plr)
if M1Turn == 1 then
Tool.Handle.Trail.Enabled = true
Tool.Handle.Slash.TimePosition = 0.3
Tool.Handle.Slash:Play()
local Animation = M1sFolder.Turn1
local Hum = plr.Character.Humanoid
local Animtrack = Hum:LoadAnimation(Animation)
Animtrack:Play()
Animtrack:GetMarkerReachedSignal("Hit"):Connect(function()
Hitbox()
end)
Animtrack.Stopped:Wait()
M1Turn += 1
EventsFolder.ServerToClient:FireClient(plr)
Tool.Handle.Trail.Enabled = false