so when i try setting Model Position to raycast result position using PivotTo() this happens:
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