Help with Custom Building System

So I made a custom building system for my game, but I need help with shifting the position of the object when your moving it around to place it. You can see in this video the system in action and it works, except when I place the chair it is placed inside the table. I need to be able to shift the Y position so it would be able to be placed on top of the table instead of inside it. The script uses mouse.Hit to determine where the object should end up.


Heres the part of the script that manages the placement:

while true do
	task.wait()
	if game.Players.LocalPlayer.pstats.PlacingObject.Value == true then
		if game.Players.LocalPlayer.pstats.Object.Value ~= nil then
			mouse.TargetFilter = game.Players.LocalPlayer.pstats.Object.Value
			local distance = (mouse.Hit.p - plr.Character.HumanoidRootPart.Position).Magnitude
			local x = math.clamp(mouse.Hit.Position.X, plr.Character.HumanoidRootPart.Position.X - MAX_RANGE, plr.Character.HumanoidRootPart.Position.X + MAX_RANGE)
			local y = math.clamp(mouse.Hit.Position.Y + SOME_Y_VALUE_TO_SHIFT_HERE, 11, 18)
			local z = math.clamp(mouse.Hit.Position.Z, plr.Character.HumanoidRootPart.Position.Z - MAX_RANGE, plr.Character.HumanoidRootPart.Position.Z + MAX_RANGE)
			local hitVec = Vector3.new(x, y, z)
			local hit = CFrame.new(hitVec)
			game.ReplicatedStorage.Remotes.InvokePlacement:FireServer(hit * orientation)
		end
	end
end

The SOME_Y_VALUE_TO_SHIFT_HERE part is just theoretical, it would be any value that would be able to shift

1 Like

So I found out Model:MoveTo() does this math for me, but it doesnt apply rotation. How could I rotate the model using MoveTo()?

You could probably set it with moveto and then change the rotation with SetPrimaryPartCFrame

Model:MoveTo()

Model:SetPrimaryPartCFrame(Model.PrimaryPart.CFrame * rotation)