Hello! I've been working on a simple building-system. I have a problem where when I move my cursor to the left (or right depending on which way I'm facing) it snaps halfway through the block instead of the mouse actually being outside of the part.
TLDR:
Join this game, Press Z, and move your mouse halfway through the block and it'll snap instead of the mouse actually being outside of the block.
https://www.roblox.com/games/1410833738/Building-Example
More information can be given via Discord - Goat#2976
local RS = game:GetService("ReplicatedStorage")
local remotes = RS:WaitForChild("Remotes")
local place = remotes:WaitForChild("Place")
local block = RS:WaitForChild("Part"):Clone()
local player = game:GetService("Players")['LocalPlayer']
local mouse = player:GetMouse()
mouse.TargetFilter = block
local building = false
local grid = 5
local function round(pos)
local flooredValue = math.floor(pos)
return (flooredValue - (flooredValue % grid))
end
game:GetService("UserInputService").InputBegan:Connect(function(key, typing)
if key.KeyCode == Enum.KeyCode.Z and not typing then
building = true
block.Parent = workspace
game:GetService("RunService").Heartbeat:Connect(function()
block.CFrame = CFrame.new(round(mouse.Hit.p.X), mouse.Hit.p.Y + block.Size.Y / 2, round(mouse.Hit.p.Z))
end)
end
end)
mouse.Button1Down:Connect(function()
if building then
place:FireServer(block.Position, block.Orientation)
end
end)

2 comments
Anyone? ;-;
I have this same problem! Someone answer this please?