RaycastResult.Instance not returning proper part?

  1. What do you want to achieve?
    Hey guys, I am working on a nice little sandbox tycoon project over my Christmas break from school. While I was making my placement system, I noticed a bug with part returned with RaycastResult.Instance. It seems that a ray I use in my placement system to detect what part is below the object will hit the correct part, but then when I place it further away from the 0, 0, 0 position in studio it doesn’t return the part directly below the object.

  2. What is the issue?


    In this video you can see I place the object just fine on the left of my plot part, but when I place it on the far right it doesn’t print that it is hitting the plot part, just that it hits the baseplate for some reason?

  3. What solutions have you tried so far?
    I have tried searching for solutions on the Dev Forum but usually I get general raycast questions and nothing related to my issue. I have also created a part to track where the ray is going, and it goes straight down, so the ray should hit the plot part before the baseplate. I am puzzled as to why it doesn’t.

Here is my function that fires the ray:

local function FireRay(cloneObject)
	local originPart = cloneObject.Hitbox
	local originPoint = cloneObject.Hitbox.Position
	local rayDirection = originPoint - Vector3.new(0, 10, 0)

	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {originPart.Parent}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	local raycastResult = workspace:Raycast(originPoint, rayDirection, raycastParams)

	if raycastResult then
		local hitpart = raycastResult.Instance
		
		print(hitpart)

		if hitpart.Name == cloneObject.Ground.Value and workspace.Plots[player.Plot_Number.Value].Plot.Owner.Value == player.Name then
			Unbind()
			placing = false
			
			return false
		else
			Unbind()
			placing = false
			
			return true
		end
	end
end

For some extra info, this is all done on the client. The only part of the placement system that is on the server is the action of placing the real object down. Not sure if firing the ray from the client affects anything but I thought I would include that. Anyways, all help here is appreciated, as I would like to know what exactly is going on here.

1 Like