I’m currently making a combat system for my zombie defense game. However, the hitboxes that are generated from my server script seem to be stacking damage.
As you can see in the videos. When I attack but don’t hit anything my damage stacks, as if the hit box was still there.
This is my module in the server script service.
module.GenerateHitBox = function(Root, Anchored, Size, Cframe, LifeTime)
local NewBox = Instance.new("Part",workspace)
NewBox.Size = Size
NewBox.CanCollide = false
NewBox.Material = Enum.Material.ForceField
NewBox.Color = Color3.new(1, 0.25098, 0)
if Anchored == true then
NewBox.Anchored = true
NewBox.CFrame = CFrame
else
local NewWeld = Instance.new("Weld",Root)
NewWeld.Part0 = NewBox
NewWeld.Part1 = Root
NewWeld.C0 = Cframe
end
if LifeTime then
Debris:AddItem(NewBox,LifeTime)
end
return NewBox
end
And here is my code in the local script for input
local CanHit = true
local HitBox1 = RemoteEvents.CreateHitBox:FireServer(RootPart,false,Vector3.new(1,1,3),CFrame.new(1.1,-0.8,2) * CFrame.Angles(math.rad(10),math.rad(40),0),0.1)
RemoteEvents.CreateHitBox.OnClientEvent:Connect(function(Part)
Part.Touched:Connect(function(hit)
if hit and hit.Parent and CanHit == true then
local TargetHum = hit.Parent:FindFirstChild("Humanoid")
local TargetHumRoot = hit.Parent:FindFirstChild("HumanoidRootPart")
if TargetHum and TargetHumRoot then
RemoteEvents.ApplyForce:FireServer(TargetHumRoot, RootPart, RootPart.CFrame.LookVector*6 + RootPart.CFrame.RightVector*2, 6, 0.4) AnimationStack = TargetHum:LoadAnimation(Animations:WaitForChild("NormalAtk"):WaitForChild("LightArmAtk"):WaitForChild("Attack2"):WaitForChild("Stagger1"))
--AnimationStack:Play()
RemoteEvents.DamageEntity:FireServer(TargetHum,10)
CanHit = false
AttackConnected = true
end
end
end)
end)
Does anyone know why the damage is stacking? If you need any more info do ask.