Problems with setting model position to raycast result position using :PivotTo()

so when i try setting Model Position to raycast result position using PivotTo() this happens:
hasf
almost all of the model goes undermap (not fully underground but you can see that most of it is underground)
and yes, i tried looking on dev hub but i couldn’t find solution.

Script:

local Debounce = false
local Player = script.Parent.Parent.Parent
local UserInputService = game:GetService("UserInputService")
local Structure = "CelestialSpawnLocation"

local RSStructures = game.ReplicatedStorage:FindFirstChild("RSStructures")

script.Parent.Activated:Connect(function()
	if Debounce == false then
		local SpaceData = Player:FindFirstChild("SpaceData")
		if SpaceData:FindFirstChild("CurrentPlanet").Value == "Outer Space" then

		else
			Debounce = true
			local raycastParams = RaycastParams.new()
			raycastParams.FilterDescendantsInstances = {Player.Character}
			raycastParams.FilterType = Enum.RaycastFilterType.Exclude
			
			local origin = Player.Character:WaitForChild("HumanoidRootPart").Position
			local direction = origin + -Player.Character:WaitForChild("HumanoidRootPart").CFrame.UpVector * 256
			
			local raycastResult = workspace:Raycast(origin, direction, raycastParams)
			
			local CloneStructure = RSStructures:FindFirstChild(Structure):Clone()
			CloneStructure.Parent = game.Workspace:FindFirstChild("PreviewStructures")
			for i, Part in pairs(CloneStructure:GetDescendants()) do
				if Part:IsA("MeshPart") and Part.Transparency <= 0.95 or Part:IsA("BasePart") and Part.Transparency <= 0.95 or Part:IsA("UnionOperation") and Part.Transparency <= 0.95 then
					Part.Transparency = 0.75
					Part.CanCollide = false
				end
			end

			CloneStructure:PivotTo(CFrame.new(raycastResult.Position)) -- this is where it sets model position to raycast result position
			CloneStructure:PivotTo(CFrame.new(CloneStructure:GetPivot().Position) * Player.Character:GetPivot().Rotation)
			script.Parent.Gui.Parent = Player.PlayerGui
			Player.PlayerGui:FindFirstChild("Gui").ConfirmButton.MouseButton1Click:Connect(function()
				for i, Part2 in pairs(CloneStructure:GetDescendants()) do
					if Part2:IsA("MeshPart") and Part2.Transparency <= 0.95 or Part2:IsA("BasePart") and Part2.Transparency <= 0.95 or Part2:IsA("UnionOperation") and Part2.Transparency <= 0.95 then
						Part2.Transparency = 0
						Part2.CanCollide = true
					end
				end
			Player.PlayerGui:FindFirstChild("Gui"):Destroy()
			script.Parent:Destroy()
			end)
			Player.PlayerGui:FindFirstChild("Gui").RemoveButton.MouseButton1Click:Connect(function()
				CloneStructure:Destroy()
				Player.PlayerGui:FindFirstChild("Gui").Parent = script.Parent
				Debounce = false
			end)
		end
	end
end)

Here is where Position Change happens and Raycast

			local raycastParams = RaycastParams.new()
			raycastParams.FilterDescendantsInstances = {Player.Character}
			raycastParams.FilterType = Enum.RaycastFilterType.Exclude
			
			local origin = Player.Character:WaitForChild("HumanoidRootPart").Position
			local direction = origin + -Player.Character:WaitForChild("HumanoidRootPart").CFrame.UpVector * 256
			
			local raycastResult = workspace:Raycast(origin, direction, raycastParams)

CloneStructure:PivotTo(CFrame.new(raycastResult.Position)) -- this is where it sets model position to raycast result position

(raycast is fully right its probably something with PivotTo()
and MoveTo() is even buggier

1 Like

Try offsetting the position of the model.
Instead of clonestructure:PivotTo(CFrame.new(raycastResult.Position)),

Try:
clonestructure:PivotTo(CFrame.new(raycastResult.Position + Vector3.new(0,REPLACE_WITH_OFFSET,0)))

no, i can’t do that because i use wall stick/gravity contoller inside my game which means downwards of player will not be always Y axis. (and because of that fact i had to use raycasting to know downwards of player)

so i found a solution. for those who have same problem or want to know how i fixed it. i just changed primary part to part which is at bottom of model.

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