I have created a placement system, but the thing that I can't seem to fix about it is that it goes ontop of other models, and doesn't, like stay touching the baseplate. Here is an image of it happening.
Here is something I tried, but it only goes down by 0.5 of a stud when you move your mouse, and that's not what I wanted.
local mouse = game.Players.LocalPlayer:GetMouse()
local tool = script.Parent
local lhit = nil
local ltarg = nil
tool.Equipped:connect(function(emouse)
local modelc = game.Lighting.Items:FindFirstChild("Mine", true)
model = modecl:Clone()
model.Parent = workspace
emouse.TargetFilter = model, game.Players.LocalPlayer.Character
emouse.Move:connect(function()
if (mouse.Hit ~= lhit) then
lhit = mouse.Hit
ltarg = mouse.Target
model:MoveTo(Vector3.new(math.ceil(emouse.Hit.X), 0.5, math.ceil(emouse.Hit.Z)))
for _,v in pairs(model:GetChildren()) do
if v.ClassName == "Part" then
v.CFrame = CFrame.new(v.Position.X, v.Position.Y, v.Position.Z) - Vector3.new(0, 0.5, 0)
end
end
end
end)
emouse.Button1Down:connect(function()
local placed = model:Clone()
placed.Hitbox:Destroy()
placed.Parent = workspace
placed.Name = "PlacedMine"
end)
end)
tool.Unequipped:connect(function()
model:Destroy()
end)

1 comment
The answer was to CFrame the model's PrimaryPart.