PartsBoundInBox Hitbox Issue

I’m trying to have the hitbox constantly update but I don’t know how. I thought about and tried using a while loop but I can’t get it to work. The hitbox(purple.Inner) is tweened for both its size and position. I looked around the devofurm but couldn’t get anything related to constantly updating partsboundinbox.

Thank you in advance!

	local purpleOverlapParameters = OverlapParams.new()
	
	local purpleHitContents = workspace:GetPartBoundsInBox(purple.Inner.CFrame, purple.Inner.Size, purpleOverlapParameters)
	local hits = {}
	for i,v in pairs(purpleHitContents) do
		local hit = v
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= player.Name then
			if not hit.Parent.Humanoid:FindFirstChild(player.Name) then
				return
			end
			hits[hit.Parent.Name] = true
			hit.Parent:FindFirstChild("Humanoid"):TakeDamage(250)
			wait(4)
			hits[hit.Parent.Name] = false
		end
	end

	game.Debris:AddItem(sphereVFX31, 1)
	game.Debris:AddItem(sphereVFX32, 1)
	game.Debris:AddItem(purple, 10)

What exactly is the issue when using a while loop?

1 Like
	local purpleOverlapParameters = OverlapParams.new()
	while purple.Inner do
		wait()
		local purpleHitContents = workspace:GetPartBoundsInBox(purple.Inner.CFrame, purple.Inner.Size, purpleOverlapParameters)
		local hits = {}
		for i,v in pairs(purpleHitContents) do
			local hit = v
			if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= player.Name then
				if not hit.Parent.Humanoid:FindFirstChild(player.Name) then
					return
				end
				hits[hit.Parent.Name] = true
				hit.Parent:FindFirstChild("Humanoid"):TakeDamage(250)
				wait(4)
				hits[hit.Parent.Name] = false
			end
		end
	end

Just doesn’t work, and I also have code below, so if I use the while loop it will never reach that part of the code(I think)

local RunService = game:GetService("RunService")
local purpleOverlapParameters = OverlapParams.new()
	
RunService.Heartbeat:Connect(function()
		local purpleHitContents = workspace:GetPartBoundsInBox(purple.Inner.CFrame, purple.Inner.Size, purpleOverlapParameters)
		local hits = {}
		for i,v in pairs(purpleHitContents) do
			local hit = v
			if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= player.Name then
				if not hit.Parent.Humanoid:FindFirstChild(player.Name) then
					return
				end
				hits[hit.Parent.Name] = true
				hit.Parent:FindFirstChild("Humanoid"):TakeDamage(250)
				wait(4)
				hits[hit.Parent.Name] = false
			end
		end
	end)

Maybe try hearbeat?

1 Like

To make the code below the while true do works you need to put the while true do inside

task.spawn(function()
	
end)
1 Like

I just tried this, the hit doesn’t take any damage

	local function purpleDetectionLoop()
		while purple.Inner do
			wait()
			local purpleOverlapParameters = OverlapParams.new()
			local purpleHitContents = workspace:GetPartBoundsInBox(purple.Inner.CFrame, purple.Inner.Size, purpleOverlapParameters)
			local hits = {}
			for i,v in pairs(purpleHitContents) do
				local hit = v
				if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= player.Name then
					if not hit.Parent.Humanoid:FindFirstChild(player.Name) then
						return
					end
					hits[hit.Parent.Name] = true
					hit.Parent:FindFirstChild("Humanoid"):TakeDamage(250)
					wait(4)
					hits[hit.Parent.Name] = false
				end
			end
		end
	end
	
	task.spawn(purpleDetectionLoop)

I tried this code and the humanoid didn’t take any damage.

My purple part is tweened and anchored. Could this have anything to do with why it isn’t working?

make sure that the hit.Parent is the players character. Preferrably add a print statement to check what the parent is.

1 Like


I’m using the code you gave me and filtered the output so that it only shows rig. I added print(v.Parent) to the code.

Have you checked whether the humanoid took damage or not through properties, because the rig’s HealthDisplayType/Distance might be disabled.

1 Like

It’s enabled and I also checked in the properties window

Could you send the exact code that was used in the video?

1 Like

I’ve been changing the code a lot but it was something similar to this:

local RunService = game:GetService("RunService")
local purpleOverlapParameters = OverlapParams.new()
	
RunService.Heartbeat:Connect(function()
		local purpleHitContents = workspace:GetPartBoundsInBox(purple.Inner.CFrame, purple.Inner.Size, purpleOverlapParameters)
		local hits = {}
		for i,v in pairs(purpleHitContents) do
			local hit = v
			if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= player.Name then
				if not hit.Parent.Humanoid:FindFirstChild(player.Name) then
					return
				end
				hits[hit.Parent.Name] = true
				hit.Parent:FindFirstChild("Humanoid"):TakeDamage(250)
				wait(4)
				hits[hit.Parent.Name] = false
			end
		end
	end)

Where was the print statement shown in the video?

1 Like

it was below local hit = v

Try putting it right above where the humanoid is supposed to take damage to see whether the issue is hitting it or dealing damage.

I just noticed a strange error thats going on right now

	task.wait(5)
	local purple = game.ServerStorage.PurpleSphereVFX3:Clone()
	purple.Parent = game.Workspace
	purple:PivotTo(sphereVFX31["8"].CFrame)

	local purpleSizeTweenInfo = TweenInfo.new(
		2, -- Time animating
		Enum.EasingStyle.Quad, -- EasingStyle
		Enum.EasingDirection.Out, -- EasingDirection
		0, -- Repitions
		false, -- Reverse post tween?
		0 -- Delay time
	)
	
	local purpleSizeTween1 = ts:Create(purple.Inner,purpleSizeTweenInfo,{Size=Vector3.new(4.28,4.28,4.28)})
	purpleSizeTween1:Play()
	local purpleSizeTween2 = ts:Create(purple.Outer1,purpleSizeTweenInfo,{Size=Vector3.new(5.74,5.77,5.75)})
	purpleSizeTween2:Play()
	local purpleSizeTween3 = ts:Create(purple.Outer2,purpleSizeTweenInfo,{Size=Vector3.new(5.74,5.77,5.75)})
	purpleSizeTween3:Play()
	local purpleSizeTween4 = ts:Create(purple.Outer3,purpleSizeTweenInfo,{Size=Vector3.new(7.11,8.18,3)})
	purpleSizeTween4:Play()
	local purpleSizeTween5 = ts:Create(purple.Outer4,purpleSizeTweenInfo,{Size=Vector3.new(6.17,6.68,6.77)})
	purpleSizeTween5:Play()

	local function waitUnanchor()
		task.wait(0.5)
		humanoidRootPart.Anchored = false
	end

	task.spawn(waitUnanchor)

	local function purpleShootTween()
		task.wait(1)
		local purpleShootTweenInfo = TweenInfo.new(
			5, -- Time animating
			Enum.EasingStyle.Quad, -- EasingStyle
			Enum.EasingDirection.Out, -- EasingDirection
			0, -- Repitions
			false, -- Reverse post tween?
			0 -- Delay time
		)

		local purpleShootGoal = {
			Position = humanoidRootPart.Position + humanoidRootPart.CFrame.LookVector * 1000
		}

		local purpleShootTween1 = ts:Create(purple.Inner, purpleShootTweenInfo, purpleShootGoal)
		purpleShootTween1:Play()
		local purpleShootTween2 = ts:Create(purple.Outer1, purpleShootTweenInfo, purpleShootGoal)
		purpleShootTween2:Play()
		local purpleShootTween3 = ts:Create(purple.Outer2, purpleShootTweenInfo, purpleShootGoal)
		purpleShootTween3:Play()
		local purpleShootTween4 = ts:Create(purple.Outer3, purpleShootTweenInfo, purpleShootGoal)
		purpleShootTween4:Play()
		local purpleShootTween5 = ts:Create(purple.Outer4, purpleShootTweenInfo, purpleShootGoal)
		purpleShootTween5:Play()
	end

	task.spawn(purpleShootTween)

	local RunService = game:GetService("RunService")
	local purpleOverlapParameters = OverlapParams.new()

	RunService.Heartbeat:Connect(function()
		local purpleHitContents = workspace:GetPartBoundsInBox(purple.Inner.CFrame, purple.Inner.Size, purpleOverlapParameters)
		local hits = {}
		for i,v in pairs(purpleHitContents) do
			local hit = v
			if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= player.Name then
				if not hit.Parent.Humanoid:FindFirstChild(player.Name) then
					return
				end
				hits[hit.Parent.Name] = true
				hit.Parent:FindFirstChild("Humanoid"):TakeDamage(250)
				wait(4)
				hits[hit.Parent.Name] = false
			end
		end
	end)
	
	game.Debris:AddItem(sphereVFX31, 1)
	game.Debris:AddItem(sphereVFX32, 1)
	game.Debris:AddItem(purple, 10)

end)

thats part of the code used in the video

See if this works:

local RunService = game:GetService("RunService")
local purpleOverlapParameters = OverlapParams.new() -- id highly suggest adding the player' character as a blacklist
local alreadyHit = {}
	
RunService.Heartbeat:Connect(function()
    local purpleHitContents = workspace:GetPartBoundsInBox(purple.Inner.CFrame, purple.Inner.Size, purpleOverlapParameters)

    for i, part in pairs(purpleHitContents) do
        local char = part.Parent
        local humanoid = char:FindFirstChild("Humanoid")

        if humanoid and table.find(alreadyHit, char) == nil then
            table.insert(alreadyHit, char)

			humanoid:TakeDamage(250)

			task.wait(4)

            if table.find(alreadyHit, char) then
               table.remove(alreadyHit, table.find(alreadyHit, char))
            end
		end
	end
end)
1 Like