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)

3 comments
This spawns the part on top of the other part. What I wanted is the top of the part that you are spawning to position on the top of the other part (the part that the mouse is pointing to).
Here is what happens in your solution: https://gyazo.com/bbacaeedf2c3b64206ce9f62c7d01b0c
sorry for the late response, but DO NOT USE POSITION, it has auto collision detection, use CFrame