Need Help Making a sword utilizing (GetPartBoundsInBox Function)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    A accurate sword that uses GetPartsBoundsInBox
  2. What is the issue?
    It isn’t accurate it sometimes damages then doesn’t on some hits or just breaks entirely
local debounce = false
local canattack = false
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local anim = Instance.new("Animation",tool)
anim.AnimationId = "rbxassetid://7652284269"
local player = script.Parent.Parent.Parent
local character = player.Character
wait()
local humanoid = character:WaitForChild("Humanoid") 
local animator = humanoid:WaitForChild("Animator")
local loadanim = animator:LoadAnimation(anim)

tool.Activated:Connect(function()
	if not debounce then
		loadanim:Play()
		debounce = true
		canattack = true
		loadanim.Stopped:wait()
		debounce = false
	end
end)

while true do
	wait()
	local ovParams = OverlapParams.new()
	ovParams.FilterDescendantsInstances = {script.Parent.Parent}
	ovParams.CollisionGroup = "Default"
	ovParams.FilterType = Enum.RaycastFilterType.Blacklist
	ovParams.MaxParts = 100
	local parts = workspace:GetPartBoundsInBox(handle.Hitbox.CFrame,handle.Hitbox.Size,ovParams)

	if canattack == true then
		for i,v in pairs(parts) do
			if v.Parent:FindFirstChild("HumanoidRootPart") then
				v.Parent.Humanoid:TakeDamage(10)
				canattack = false
			elseif not v.Parent:FindFirstChild("HumanoidRootPart") then
				loadanim.Stopped:wait()
				canattack = false
			end
		end
	end
end
1 Like

The hitbox would get every part in the character you attacked, Is there some way to prevent this?

This post is very old and I am a much better scripter now but there is 2 ways to prevent this

Way 1 - For multiple argets
Create a table when activating the tool any humanoid that was hit add them to the table this allows you to be able to check any target that was hit and ignore them instead of using canattack you would have canattack for each humanoid

Way 2 - Singular
Check if the humanoid that was hit is already dead if it is then you would just ignore if it isnt then you would damage and deactivate the weapon

2 Likes