It printed this.
Same issue with no detection.
However, I did come up with something myself last night and I think I was pretty close. Instead of using the hitbox that was welded to the player’s rootpart, I cloned and repositioned a preset hitbox which was inside of the tool, and put it inside one of my workspace folders and used CFrame to position it in front of the player. I figured the welded hitbox method might be inefficient for GetPartsInPart() detection, so I tried this and tested it. I was actually able to get a few hits in. I got excited, but after enough hits it stopped creating new hitboxes.
Here’s the code that somewhat works. The hitbox spawning stuff you can find in the Attack() function, and the only other thing I changed was replacing some task.waits with task.delays later in the script, which fixed the dissonance between the swing animation and the Attack() function.
local tool = script.Parent
local hitbox = tool.HitboxPart
local g
-- hitbox weld stuff
tool.Equipped:Connect(function()
local char = tool.Parent
local root = char:WaitForChild("HumanoidRootPart")
if root ~= nil and root:FindFirstChild("HitboxPart") ~= nil then
root:FindFirstChild("HitboxPart"):Destroy()
end
if root ~= nil then
g = hitbox:Clone()
g.Anchored = false
g.Parent = root
local W = Instance.new("Weld")
g.CFrame = root.CFrame * CFrame.new(0,0,-2.5)
W.Part0 = root
W.Part1 = g
W.C0 = root.CFrame:Inverse()
W.C1 = g.CFrame:Inverse()
W.Parent = g
--[[local Y = Instance.new("Weld")
Y.Part0 = root
Y.Part1 = g
Y.C0 = CFrame.new(0, 0, 0)
Y.Parent = Y.Part0--]]
end
-- restore a new hitbox
if tool:FindFirstChild("HitboxPart") == nil then
local newhit = g:Clone()
newhit:ClearAllChildren()
newhit.Parent = tool
newhit.Anchored = true
end
end)
-- get rid of the old hitbox
tool.Unequipped:Connect(function()
if g then g:Destroy()
g = nil
end
end)
-- more variables
local db = false
local canHit = false
local randomSlash = 1
local equip
local slash
local idle
-- folders
local anims = script.Parent.Animations
local sounds = script.Parent.Sounds
local ws = game:GetService("Workspace")
local box = tool.box
-- start up the animation stuff
script.Parent.Equipped:Connect(function()
sounds.Equip:Play()
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not equip then equip = humanoid:LoadAnimation(anims.Equip) end
equip:Play()
if not idle then idle = humanoid:LoadAnimation(anims.Idle) end
idle.Priority = Enum.AnimationPriority.Movement
idle:Play()
end)
-- light attack function
script.Parent.Activated:Connect(function()
local char = tool.Parent
if char.Stunned.Value == false and char.Dashing.Value == false and not db then
db = true
idle:Stop()
local function Attack()
if db == true then
if not canHit then
canHit = true
local effect = script.Parent.Handle.Blood
local btrail = script.Parent.Handle.BloodTrail
local oparams = OverlapParams.new()
oparams.FilterType = Enum.RaycastFilterType.Exclude
oparams.FilterDescendantsInstances = {char}
local humanoidsDamaged = {}
local boxc = box:Clone() -- box is an identical version of the original hitbox, but anchored and unwelded. its parent is the tool.
box.Parent = ws.Scripted -- Scripted is a folder in the workspace
box.CFrame = char.HumanoidRootPart.CFrame * CFrame.new(0,0,-3.5)
local hits = ws:GetPartsInPart(box,oparams)
for i = 1, #hits do
print(hits[i]:FindFirstAncestorWhichIsA('Model'))
if hits[i].Parent ~= char and hits[i].Parent:FindFirstChild("Humanoid") and hits[i].Parent:FindFirstChild("Dashing") and char.Stunned.Value == false then
print("check 1 success")
if hits[i].Parent.Dashing.Value == false and not table.find(humanoidsDamaged, hits[i].Parent.Parent) then
table.insert(humanoidsDamaged, hits[i].Parent.Parent)
print("check 2 success")
local hitSFX = Instance.new("Sound",hits[i].Parent.Head);
hitSFX.SoundId = "rbxassetid://566593606"; hitSFX:Play()
hits[i].Parent.Humanoid:TakeDamage(5)
-- I don't know any better way to do this
local function stunhum()
hits[i].Parent:FindFirstChild("Stunned").Value = true
hits[i].Parent.Humanoid.WalkSpeed = hits[i].Parent.Humanoid.WalkSpeed / 2
local stunnum = math.random(1, 4)
local stunanim = hits[i].Parent.Humanoid:LoadAnimation(anims["Damaged".. stunnum])
stunanim:Play()
local lspart1 = tool.Handle.BLOOD02:Clone()
local lspart2 = tool.Handle.BLOOD03:Clone()
local lssound = tool.Sounds.Lifesteal:Clone()
lspart1.Parent = hits[i].Parent.Torso
lspart2.Parent = hits[i].Parent.Torso
lssound.Parent = hits[i].Parent.Torso
task.delay(.5,function()
hits[i].Parent:FindFirstChild("Stunned").Value = false
hits[i].Parent.Humanoid.WalkSpeed = hits[i].Parent.Humanoid.WalkSpeed * 2
end)
-- blood drain stuff, kinda messy
task.delay(2,function()
hits[i].Parent.Humanoid:TakeDamage(1)
char.Humanoid:TakeDamage(-1)
lssound:Play()
end)
task.delay(2.1,function()
hits[i].Parent.Humanoid:TakeDamage(1)
char.Humanoid:TakeDamage(-1)
end)
task.delay(2.2,function()
hits[i].Parent.Humanoid:TakeDamage(1)
char.Humanoid:TakeDamage(-1)
end)
task.delay(2.3,function()
hits[i].Parent.Humanoid:TakeDamage(1)
char.Humanoid:TakeDamage(-1)
end)
task.delay(2.4,function()
hits[i].Parent.Humanoid:TakeDamage(1)
char.Humanoid:TakeDamage(-1)
end)
task.delay(4,function()
lspart1:Destroy()
lspart2:Destroy()
lssound:Destroy()
end)
end
stunhum()
effect.Enabled = true
btrail.Enabled = true
local slashfx = tool.Effects.Slash.Attachment:Clone()
slashfx.Parent = hits[i].Parent:FindFirstChild("HumanoidRootPart")
local r = math.random(-360,360)
slashfx.slash.Rotation = NumberRange.new(r)
task.delay(0.3,function()
slashfx:Destroy()
end)
end
task.delay(0.4,function()
effect.Enabled = false
btrail.Enabled = false
canHit = false
box.Parent = tool
end)
end
end
end
end
end
local char = tool.Parent
local root = char:WaitForChild("HumanoidRootPart")
g = root:FindFirstChild("HitboxPart")
Attack()
-- slashes arent so random anymore
script.Parent.Handle.Trail.Enabled = true
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not slash then
slash = humanoid:LoadAnimation(anims["Attack".. randomSlash])
if randomSlash == 4 then
randomSlash = 1
else
randomSlash += 1
end
end
slash:Play()
local val = tool.Parent.Attacking
val.Value = true
task.wait(.2)
sounds.Slash:Play()
task.wait(.4)
if slash then
slash = nil
end
script.Parent.Handle.Trail.Enabled = false
db = false
idle:Play()
val.Value = false
end
end)
-- stop animations
script.Parent.Unequipped:Connect(function()
if idle then idle:Stop() end
if equip then equip:Stop()
if slash then slash:Stop() end
end
end)
Here’s what that prints:
The issue seems to be something with the cleanup of the clones. There were a couple leftover in the Scripted folder, and I could see them sitting out in the open after I was done fighting the NPC. That’s right when it stopped summoning new clones.
I think it has something to do with the boxc variable being sloppily reassigned to something new, and then it messes up the whole function. And, something I just noticed when writing this is that the original box disappeared from the tool. I was way too tired to figure it out last night, so I called it a day knowing most of the issues were fixed.
Here’s the code in my original .Touched script, if you’re still wondering about that.
local tool = script.Parent
local hitbox = tool.HitboxPart
local g
tool.Equipped:Connect(function()
local char = tool.Parent
local root = char:WaitForChild("HumanoidRootPart")
if root ~= nil and root:FindFirstChild("HitboxPart") ~= nil then
root:FindFirstChild("HitboxPart"):Destroy()
end
if root ~= nil then
g = hitbox:Clone()
g.Anchored = false
g.Parent = root
local W = Instance.new("Weld")
g.CFrame = root.CFrame * CFrame.new(0,0,-2.5)
W.Part0 = root
W.Part1 = g
W.C0 = root.CFrame:Inverse()
W.C1 = g.CFrame:Inverse()
W.Parent = g
--[[local Y = Instance.new("Weld")
Y.Part0 = root
Y.Part1 = g
Y.C0 = CFrame.new(0, 0, 0)
Y.Parent = Y.Part0--]]
end
if tool:FindFirstChild("HitboxPart") == nil then
local newhit = g:Clone()
newhit:ClearAllChildren()
newhit.Parent = tool
newhit.Anchored = true
end
end)
tool.Unequipped:Connect(function()
if g then g:Destroy()
g = nil
end
end)
local db = false
local canHit = false
local randomSlash = 1
local equip
local slash
local idle
local anims = script.Parent.Animations
local sounds = script.Parent.Sounds
script.Parent.Equipped:Connect(function()
sounds.Equip:Play()
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not equip then equip = humanoid:LoadAnimation(anims.Equip) end
equip:Play()
if not idle then idle = humanoid:LoadAnimation(anims.Idle) end
idle.Priority = Enum.AnimationPriority.Movement
idle:Play()
end)
script.Parent.Activated:Connect(function()
local char = tool.Parent
if char.Stunned.Value == false and not db then
db = true
idle:Stop()
local function Attack(hit)
if db then
if not canHit then
canHit = true
local effect = script.Parent.Handle.Blood
local btrail = script.Parent.Handle.BloodTrail
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Dashing").Value == false and char.Stunned.Value == false then
local hitSFX = Instance.new("Sound",hit.Parent.Head); hitSFX.SoundId = "rbxassetid://566593606"; hitSFX:Play()
hit.Parent.Humanoid:TakeDamage(5)
local function stunhum()
hit.Parent:FindFirstChild("Stunned").Value = true
hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed / 2
local stunnum = math.random(1,4)
if stunnum == 1 then
local stunanim = hit.Parent.Humanoid:LoadAnimation(anims.Damaged1)
stunanim:Play()
elseif stunnum == 2 then
local stunanim = hit.Parent.Humanoid:LoadAnimation(anims.Damaged2)
stunanim:Play()
elseif stunnum == 3 then
local stunanim = hit.Parent.Humanoid:LoadAnimation(anims.Damaged3)
stunanim:Play()
elseif stunnum == 4 then
local stunanim = hit.Parent.Humanoid:LoadAnimation(anims.Damaged4)
stunanim:Play()
end
local lspart1 = tool.Handle.BLOOD02:Clone()
local lspart2 = tool.Handle.BLOOD03:Clone()
local lssound = tool.Sounds.Lifesteal:Clone()
lspart1.Parent = hit.Parent.Torso
lspart2.Parent = hit.Parent.Torso
lssound.Parent = hit.Parent.Torso
delay(.5,function()
hit.Parent:FindFirstChild("Stunned").Value = false
hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed * 2
end)
delay(2,function()
hit.Parent.Humanoid:TakeDamage(1)
char.Humanoid:TakeDamage(-1)
lssound:Play()
end)
delay(2.1,function()
hit.Parent.Humanoid:TakeDamage(1)
char.Humanoid:TakeDamage(-1)
end)
delay(2.2,function()
hit.Parent.Humanoid:TakeDamage(1)
char.Humanoid:TakeDamage(-1)
end)
delay(2.3,function()
hit.Parent.Humanoid:TakeDamage(1)
char.Humanoid:TakeDamage(-1)
end)
delay(2.4,function()
hit.Parent.Humanoid:TakeDamage(1)
char.Humanoid:TakeDamage(-1)
end)
delay(4,function()
lspart1:Destroy()
lspart2:Destroy()
lssound:Destroy()
end)
end
stunhum()
effect.Enabled = true
btrail.Enabled = true
local slashfx = tool.Effects.Slash.Attachment:Clone()
slashfx.Parent = hit.Parent:FindFirstChild("HumanoidRootPart")
local r = math.random(-360,360)
slashfx.slash.Rotation = NumberRange.new(r,r)
wait(0.3)
slashfx:Destroy()
end
wait(0.4)
effect.Enabled = false
btrail.Enabled = false
canHit = false
end
end
end
local char = tool.Parent
local root = char:WaitForChild("HumanoidRootPart")
g = root:FindFirstChild("HitboxPart")
g.Touched:Connect(Attack)
script.Parent.Handle.Trail.Enabled = true
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not slash then
if randomSlash == 1 then
slash = humanoid:LoadAnimation(anims.Attack1)
randomSlash = 2
elseif randomSlash == 2 then
slash = humanoid:LoadAnimation(anims.Attack2)
randomSlash = 3
elseif randomSlash == 3 then
slash = humanoid:LoadAnimation(anims.Attack3)
randomSlash = 4
elseif randomSlash == 4 then
slash = humanoid:LoadAnimation(anims.Attack4)
randomSlash = 1
end
end
slash:Play()
local val = tool.Parent.Attacking
val.Value = true
wait(.2)
sounds.Slash:Play()
wait(.4)
if slash then
slash = nil
end
script.Parent.Handle.Trail.Enabled = false
db = false
idle:Play()
val.Value = false
end
end)
script.Parent.Unequipped:Connect(function()
if idle then idle:Stop() end
if equip then equip:Stop()
if slash then slash:Stop() end
end
end)