I don’t like the idea of creating a hitbox and slap it on the tool itself and try to recreate a fighting style hit box but the hit box part is cleary doesn’t work please tell me what did I do wrong
Edit: I know what I did wrong now, I called the reachsignal after the track ended which is why the hitbox doesn’t fire but then comes a new problem. If somehow the hitbox is hit by the player it will just completely glitch out (at the end of the video my studio crashed)
I’m still new to Lua coding in general and I feel like there’s a better way to achieve the same result I want if you could please give me an alternative way of creating a hitbox
local tool = script.Parent
local idleanim = Instance.new("Animation")
idleanim.AnimationId = "rbxassetid://82389743504697"
local slashanim1 = Instance.new("Animation")
slashanim1.AnimationId = "rbxassetid://117195817124320"
local slashanim2 = Instance.new("Animation")
slashanim2.AnimationId = "rbxassetid://81801466608249"
local Debounce = false
local slashCombo = 1
local Damage = 35
local SwingSound = script.Parent.Handle.sword_swing_fast_whoosh_blade_ring_001
local canDamage = false
local idletrack
local slahtrack
tool.Equipped:Connect(function()
tool.Handle.Anchored = false
idletrack = script.Parent.Parent.Humanoid:LoadAnimation(idleanim)
idletrack.Priority = Enum.AnimationPriority.Action
idletrack.Looped = true
idletrack:Play()
end)
tool.Unequipped:Connect(function()
if idletrack then
idletrack:Stop()
end
end)
tool.Activated:Connect(function()
if Debounce == false then
Debounce = true
if slashCombo == 1 then
slahtrack = script.Parent.Parent.Humanoid:LoadAnimation(slashanim1)
slahtrack.Priority = Enum.AnimationPriority.Action2
slahtrack.Looped = false
slahtrack:Play()
SwingSound:Play()
slahtrack:GetMarkerReachedSignal("Hit"):Connect(function(paramString)
local Hitbox = Instance.new("Part")
Hitbox.Size = Vector3.new(5, 5, 5)
Hitbox.Transparency = .5
Hitbox.Color = Color3.new(1, 0, 0)
Hitbox.CanCollide = false
Hitbox.Anchored = true
Hitbox.CFrame = script.Parent.Parent.HumanoidRootPart.CFrame * CFrame.new(0, 0, -5)
Hitbox.Parent = workspace
Hitbox.Touched:Connect(function(Target)
if Target.Parent then
if Target.Parent:FindFirstChild("Humanoid") then
if canDamage == true then
return
end
canDamage = true
Target.Parent.Humanoid:TakeDamage(Damage)
slahtrack.Stopped:wait()
canDamage = false
Hitbox:Destroy()
end
end
end)
end)
slashCombo = 2
slahtrack.Stopped:wait()
Debounce = false
elseif slashCombo == 2 then
slahtrack = script.Parent.Parent.Humanoid:LoadAnimation(slashanim2)
slahtrack.Priority = Enum.AnimationPriority.Action2
slahtrack.Looped = false
slahtrack:Play()
SwingSound:Play()
slahtrack:GetMarkerReachedSignal("Hit"):Connect(function(paramString)
local Hitbox = Instance.new("Part")
Hitbox.Size = Vector3.new(5, 5, 5)
Hitbox.Transparency = .5
Hitbox.Color = Color3.new(1, 0, 0)
Hitbox.CanCollide = false
Hitbox.Anchored = true
Hitbox.CFrame = script.Parent.Parent.HumanoidRootPart.CFrame * CFrame.new(0, 0, -5)
Hitbox.Parent = workspace
Hitbox.Touched:Connect(function(Target)
if Target.Parent then
if Target.Parent:FindFirstChild("Humanoid") then
if canDamage == true then
return
end
canDamage = true
Target.Parent.Humanoid:TakeDamage(Damage)
slahtrack.Stopped:wait()
canDamage = false
Hitbox:Destroy()
end
end
end)
end)
slashCombo = 1
slahtrack.Stopped:wait()
Debounce = false
end
end
end)
tool.AncestryChanged:Connect(function(parent)
if parent == workspace then
wait(3)
tool.Handle.Anchored = true
end
end)