Help With GetTouchingParts

The script is not detecting the ball touching the part is because I am using a tween to move the ball. Tweens do not simulate the Roblox physics engine, so the touched event will not fire when the ball reaches its target.

To fix this, I can used the GetTouchingParts() function instead. This function will return a list of all the parts that are currently touching the specified part. I can then check this list to see if the ball is touching the part you want it to be touching.

The problem is that the ball is not being detected can someone help me

-- SERVER SCRIPT LOCATED IN SERVERSCRIPTSERVICE
local bladeBall = workspace.BladeBall
local onangeHitBox = workspace.OnangeHitBox
local blueHitBox = workspace.BlueHitBox
local bladeBallSpawn = workspace.BladeBallSpawn
local particleO = onangeHitBox.Attachment.ParticleEmitter
local particleB = blueHitBox.Attachment.ParticleEmitter

-- Function to reset the ball's position
local function resetBallPosition()
	bladeBall.Transparency = 1
	bladeBall.Highlight.OutlineTransparency = 1
	bladeBall.CFrame = bladeBallSpawn.CFrame
	wait(3)
	bladeBall.Highlight.OutlineTransparency = 0
	bladeBall.Transparency = 0
end

-- Function to make a particle effect for PartO
local function createParticleO()
	particleO:Clear()
	particleO:Emit(1) -- number of particles emitted
end

-- Function to make a particle effect for PartB
local function createParticleB()
	particleB:Clear()
	particleB:Emit(1) -- number of particles emitted
end

-- Ball touch events
while wait(1) do
	local function GetTouchingParts(part)
		local connection = bladeBall.Touched:Connect(function() end)
		local results = part:GetTouchingParts()
		connection:Disconnect()
		return results
	end

	local results = GetTouchingParts(workspace.OnangeHitBox)
	for i, v in pairs(results) do
		if v == onangeHitBox then
			createParticleO()
			resetBallPosition()
		elseif v == blueHitBox then
			createParticleB()
			resetBallPosition()
		end
	end
end

Have you tried to use workspace:GetPartsInPart()?

Red lines appear when I try that

Here’s some information about that workspace method:

Ok when I recode it to this fine but how do I make it work if touches the blueHitBox

	local results = GetTouchingParts(workspace.OnangeHitBox)
	for i, v in pairs(results) do
		if v == bladeBall then
			createParticleO()
			resetBallPosition()
		end
	end
end

Never mind I found how do to it

You should share the solution in the original post or the solution post, that way when people look for the same problem, your post can help them. I’m glad you figured it out, though.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.