I have a grid system that works (almost) fine. The problem is, when I move the plot a little, the building blocks doesn’t follow the grids. Are there any way to do so that the block can always follow the grids no matter where the plot is?
Not following the grid: Imgur: The magic of the Internet.
Here I’ve moved the plot a little, so now it follows the grid: Imgur: The magic of the Internet.
Btw, the grids is just a texture.
Script:
repeat wait() until game:IsLoaded()
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Snap = 4
local Rotation = 0
local Event = Player.PlayerGui:WaitForChild("GuiEvents").OpenBuildMode
function SnapToGrid(Position, Snap)
local Value = Snap * math.round(Position / Snap)
return Value
end
function SnapToVerticalGrid(Position, Snap)
local Value = Snap * math.floor(Position / Snap)
return Value
end
local Block = game.Workspace.BuildMode.Walls.Default.Wall.Block
local Hitbox = game.Workspace.BuildMode.Walls.Default.Wall.Block
Block.CanCollide = false
Block.CastShadow = false
Block.Transparency = 0.5
local MousePosition = Instance.new("Vector3Value", Player)
MousePosition.Name = "MousePosition"
local TweenInfo1 = TweenInfo.new(0.35, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0)
UserInputService.InputChanged:Connect(function()
if not Event then return end
if Mouse.Target and Event.Opened.Value == true then
if Mouse.Target.Parent == game.Workspace.Plots or Mouse.Target.Parent == game.Workspace.Plots.Items then
MousePosition = Mouse.Hit
TweenService:Create(Hitbox, TweenInfo1, {Position = Vector3.new(SnapToGrid(MousePosition.X, Snap), SnapToVerticalGrid(MousePosition.Y, Snap) + Hitbox.Size.Y/2, SnapToGrid(MousePosition.Z, Snap))}):Play()
elseif Mouse.Target.Parent == Player.Character then
Mouse.TargetFilter = Player.Character
elseif Mouse.Target == Block then
Mouse.TargetFilter = Block
end
end
end)