I'm trying to make a placement system, however I'm not sure how to place the top of the part on the top of another part. I want it placed on top because if it placed the middle somewhere then there would be a huge block coming out of the ground. Here is my script which works, but it places the middle of the part instead of the top.
local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local Player = Players.LocalPlayer local Mouse = Player:GetMouse() local Click = script.Parent Click.MouseButton1Down:Connect(function() local Placed = false local Cancelled = false Mouse.Button1Down:Connect(function() Placed = true end) UserInputService.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.Q then Cancelled = true end end) local Baseplate = Instance.new("Part") Baseplate.Size = Vector3.new(150, 10, 150) Baseplate.Anchored = true Baseplate.Parent = workspace repeat wait() if Mouse.TargetFilter ~= Baseplate then Mouse.TargetFilter = Baseplate end local Character = Player.Character local MousePosition = Mouse.Hit.p if Mouse.Target ~= Baseplate and Mouse.Target then if Mouse.Target:IsA("Terrain") then Baseplate.CFrame = CFrame.new(MousePosition.X, Mouse.Target.Size.Y - Mouse.Target.Size.Y*0.9, MousePosition.Z) end end until Placed == true or Cancelled == true if Cancelled == true then Baseplate:Destroy() elseif Placed == true then script.Parent.Parent.Parent:Destroy() end end)
if the 2 parts never rotate, then its simple arithmetic
local PartToSpawn = Instance.new("Part", workspace) --modify part properties and whatnot local Part2 = workspace.Despacito -- part to spawn ontop of local Y = Part2.Position.Y + (Part2.Size.Y/2) + (PartToSpawn.Size.Y/2)-- final result
if only the part to teleport to is rotating is a little more complicated
local PartToSpawn = Instance.new("Part", workspace) --modify part properties and whatnot local Part2 = workspace.Despacito -- part to spawn ontop of local CF = Part2.CFrame * (Part2.CFrame.topVector * Part2.Size.Y)-- final result
if both rotate its too complicated for me :\