Help with a simple item spawner!

Hello there developers and I hope you are having a good day! I have made a simple item spawning system with the min and max XYZ coordinates and it works great however I am unsure on how I can stop this system from spawning through walls. I was thinking I could detect this using the RayCast I made but any help is deeply appreciated!

	local Part = workspace.Bed:Clone()
	Part.Parent = workspace
	local RandomPosition = Vector3.new(math.random(-175,155),19,math.random(-30,170))
	local Raytoground = Ray.new(RandomPosition,Vector3.new(0,-10000,0))

	local PartOnRay,PositionOnRay= workspace:FindPartOnRay(Raytoground) 

	if PartOnRay and PositionOnRay then
		Part:PivotTo(CFrame.new(PositionOnRay))
	end

bug

Raycasting is one way to do it, but using Workspace:GetPartsInPart() is better for detecting if something was spawned inside another part.

Something I’m noticing in your code is that you get where the part is, and you move that new part to that position without accounting for the size of the part you are moving. If you are moving a model using GetBoundingBox() may be of use to account for all of it.

1 Like

Ah thank you very much; that’s the function I was looking for!

1 Like

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