I’m making a script that rounds the position of your mouse when you click it to multiples of four. Its like the block placement system in TheDevKing’s Minecraft video, except my script only creates new parts on the x and z axes when I click in two directions; the other two directions just make me tower upward. Here’s the script:
(I have a separate local script that sends the mousePos to the server script)
(FistsClicked is a remote event)
local fistsClicked = game.ReplicatedStorage["Fists-Clicked"]
fistsClicked.OnServerEvent:Connect(function(player, mousepos)
local x = 4 * math.floor(mousepos.x/4 + 0.5)
local y = 4 * math.floor(mousepos.y/4 + 0.5)
local z = 4 * math.floor(mousepos.z/4 + 0.5)
local roundedpos = Vector3.new(x, y - 2, z)
local part = Instance.new("Part")
part.Size = Vector3.new(4, 4, 4)
part.Position = roundedpos
part.Parent = workspace
part.Anchored = true
local health = Instance.new("IntValue")
health.Name = "Health"
health.Value = 10
health.Parent = part
end)
Is there any way I could detect when to floor or ceil the coordinates based of which way the player wants to build?