So, I am making an advanced raft survival game and one of the tools in the game is a building tool. I need to round the position of the part that I place to the nearest stud for that tool though. The only method I have found is math.floor(var + 0.5)
. This method I am pretty sure is making the part offset by a few pixels and this happens. You cannot place blocks in the negative axis because of the small offset as shown near the end of this video:
oh and here’s the script for placin the block:
wait()
script.Parent.Activated:Connect(function()
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local NewPart = Instance.new("Part")
NewPart.Size = Vector3.new(1,1,1)
NewPart.Parent = workspace
NewPart.Anchored = true
NewPart.Position = Vector3.new(math.floor(Mouse.Hit.Position.X + 0.5), math.floor(Mouse.Hit.Position.Y + 0.5), math.floor(Mouse.Hit.Position.Z + 0.5))
NewPart.Position = Vector3.new(NewPart.Position.X, NewPart.Position.Y + NewPart.Size.Y/2, NewPart.Position.Z)
print(NewPart.Position)
end)
I’m pretty new to scripting in lua, So sorry if the answer is obvious.