Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why do 3 of my 6 raycasts fired in the directions of a cube not work correctly?

For my block placing in a grid system, I made 6 raycasts that fire off in all 6 directions to find a nearby block and weld to it. This works, however it doesn't for the Left, Right, and Front raycasts, they can't detect the other blocks, yet they can detect other things like my character. Any help?

Place.OnServerEvent:Connect(function(Player,Block,Position)
	local function Weld(Part0,Part1)
		local Weld = Instance.new("WeldConstraint")
		Weld.Part0 = Part0
		Weld.Part1 = Part1
		Weld.Parent = Part0
	end
	if Player.Character then
		local Character = Player.Character
		local Build = Character:FindFirstChild("Build")
		if Build then
			if Block.Parent == Placeables then
				local ClonedBlock = Block:Clone()
				ClonedBlock.Anchored = true
				ClonedBlock.Position = Module.Grid(Position)
				ClonedBlock.Parent = PlacedBlocks
				local RayCastParameters = RaycastParams.new()
				RayCastParameters.FilterDescendantsInstances = {ClonedBlock}
				RayCastParameters.FilterType = Enum.RaycastFilterType.Blacklist
				local RayLeft = workspace:Raycast(Module.Grid(Position),Vector3.new(4,0,0),RayCastParameters)
				local RayRight = workspace:Raycast(Module.Grid(Position),Vector3.new(-4,0,0),RayCastParameters)
				local RayUp = workspace:Raycast(Module.Grid(Position),Vector3.new(0,4,0),RayCastParameters)
				local RayDown = workspace:Raycast(Module.Grid(Position),Vector3.new(0,-4,0),RayCastParameters)
				local RayFront = workspace:Raycast(Module.Grid(Position),Vector3.new(0,0,4),RayCastParameters)
				local RayBack = workspace:Raycast(Module.Grid(Position),Vector3.new(0,0,-4),RayCastParameters)
				if RayLeft then
					local HitPart = RayLeft.Instance
					print(HitPart)
					Weld(ClonedBlock,HitPart)
				end
				if RayRight then
					local HitPart = RayRight.Instance
					print(HitPart)
					Weld(ClonedBlock,HitPart)
				end
				if RayUp then
					local HitPart = RayUp.Instance
					print(HitPart)
					Weld(ClonedBlock,HitPart)
				end
				if RayDown then
					local HitPart = RayDown.Instance
					print(HitPart)
					Weld(ClonedBlock,HitPart)
				end
				if RayFront then
					local HitPart = RayFront.Instance
					print(HitPart)
					Weld(ClonedBlock,HitPart)
				end
				if RayBack then
					local HitPart = RayBack.Instance
					print(HitPart)
					Weld(ClonedBlock,HitPart)
				end
				wait()
				ClonedBlock.Anchored = false
			end
		end
	end
end)

1 answer

Although not very effect, I used Region3 instead of Raycasts, and it worked!

This discussion is preserved as it was. New answers, comments, and votes are closed.