FindPartOnRayWithWhitelist Doesn't Work On Newly Spawned Parts

When I call FindPartOnRayWithWhitelist on a part that has just been spawned, it doesn’t detect the part unless I add a delay before casting. This is not an issue with FindPartOnRayWithIgnoreList.

wait(0.5)

game.Workspace.ChildAdded:Connect(function(Part)
	local Origin = Part.Position + Vector3.new(0, 1, 0)
	local Ray1 = Ray.new(Origin, Vector3.new(0, -2, 0)) 
	
	-- Works if there is a delay
	-- wait(0.1)
	
	local h, p = game.Workspace:FindPartOnRayWithWhitelist(Ray1, {Part})
	
	print(h)
    -- Prints nil with no delay
end)

wait(0.5)

local Part = Instance.new("Part")
Part.CFrame = CFrame.new(0, 10, 0)
Part.Anchored = true
Part.Parent = game.Workspace
3 Likes

I’m having a very similar issue. I use FindPartOnRayWithWhitelist and bind it to RenderStep. When a part on the whitelist is clicked, the server deletes the part and spawns another one directly behind it. Even though I’m casting a ray with each frame, the FindPartOnRayWithWhitelist still prints out the deleted block as though it’s still getting hit with the ray. It’s only when I move the mouse away from where the part used to exist is when the ray recognizes the part as being destroyed and starts printing out the newly spawned part.

1 Like