-
What do you want to achieve? Make a 4 stud grid block placement system
-
What is the issue? The block is not properly aligned on the baseplate.
I want it to align like this:
Not like this:
I don’t know how to fix this issue. Here’s my code:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Part = game.ReplicatedStorage.block
local ts = game:GetService("TweenService")
local partBlacklist = {"SpawnLocation"}
-- functions
local function round(vector,grid)
return Vector3.new(
math.floor(vector.X/grid+.5)*grid,
math.floor(vector.Y/grid+.5)*grid,
math.floor(vector.Z/grid+.5)*grid)
end
function tweenpos(part: Instance, x: CFrame.X, y: CFrame.Y, z: CFrame.Z)
local tween = ts:Create(part, TweenInfo.new(0.1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {CFrame = CFrame.new(x, y, z)})
tween:Play()
end
local function Move()
Part.Parent = workspace
mouse.TargetFilter = Part
local pos = round(mouse.Hit.p, 4)
tweenpos(Part, pos.X, math.round(mouse.Hit.p.Y + 2), pos.Z)
end
-- events
script.Parent.Activated:Connect(function ()
if mouse.Target == nil then return end
if mouse.Target.Parent.Parent == workspace.spawn or table.find(partBlacklist, mouse.Target.Name) ~= nil then
local c = game.ReplicatedStorage.TextLabel:Clone()
c.Parent = player.PlayerGui.ScreenGui
player.PlayerGui.ScreenGui.error:Play()
wait(3)
c:Destroy()
return
end
local pos = Part.Position
local cf = CFrame.new(pos.X, pos.Y, pos.Z)
game.ReplicatedStorage.placeblock:FireServer(player, cf, game.JobId)
end)
script.Parent.Equipped:Connect(function ()
repeat
wait()
Move()
until script.Parent.Parent == player.Backpack
Part.Parent = game.ReplicatedStorage
end)
script.Parent.Unequipped:Connect(function ()
Part.Parent = game.ReplicatedStorage
end)