Hey there.
I am using a building placement system for a game I am creating. This requires me to be able to snap the placement of buildings to fine positions. By default, the grid size is set to 0.25 studs. So, anywhere in the below code that you see “gridSize”, just replace that with 0.25.
This is the code in question:
local roundedPosition = Vector3.new(
math.floor((hit.X + gridSize / 2) / gridSize) * gridSize,
math.floor((hit.y + gridSize / 2) / gridSize) * gridSize + script.Parent:FindFirstChildOfClass("Model").PrimaryPart.Size.Y/2,
math.floor((hit.Z + gridSize / 2) / gridSize) * gridSize
)
Essentially, it tries to take your mouse’s hit position and round it to a number. This works great, and produces a desired snapping result.
However, at lower increments (such as the default 0.25), it is seemingly not calculated the same between the server and client.
An example is how the Client registered the roundedPosition at:
-7.25, -459.75, 7 - Client
Whereas the exact same code, without moving my mouse, calculated the roundedPosition at:
-7.199999809265137, -459.70001220703125, 7 - Server
Or, from another example:
-1.25, -459.75, 7 - Client
-1.2000000476837158, -459.70001220703125, 6.900000095367432 - Server
I can promise with absolute certainty that the code is the exact same on the Server and Client scripts.
Is there any reason why this is happening?