local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(3,5,7)
part.CanCollide = false
part.CanQuery = false
part.Transparency=0.5
part.Material = Enum.Material.Brick
part.Color = Color3.fromRGB(255, 255, 255)
part.Parent = workspace
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local grid = 4
local orientation=Vector3.new(0,0,0)
local lastOrientation=orientation
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Build = ReplicatedStorage.Events.Build
local function SnapToGrid(pos, blockSize)
local gridX = blockSize.X
local gridY = blockSize.Y
local gridZ = blockSize.Z
if lastOrientation~=orientation then
print('part rotated')
lastOrientation=orientation
gridX = blockSize.X
gridY = blockSize.Y
gridZ = blockSize.Z
end
return Vector3.new(
math.floor(pos.X / gridX + 0.5) * gridX,
math.floor(pos.Y / gridY + 0.5) * gridY,
math.floor(pos.Z / gridZ + 0.5) * gridZ
)
end
RunService.RenderStepped:Connect(function()
if mouse.Hit then
local snapped = SnapToGrid(mouse.Hit.Position,part.Size)
part.CFrame = CFrame.new(snapped + Vector3.new(0, part.Size.Y / 2, 0))
part.Orientation=orientation
end
end)
mouse.Button1Down:Connect(function()
local data = {
Position = part.Position,
Size = part.Size,
Color = part.Color,
Material = part.Material.Name,
Orientation=part.Orientation
}
Build:FireServer(data)
end)
mouse.Button2Down:Connect(function()
orientation=Vector3.new(0,part.Orientation.Y+90,0)
end)```
#need help making the block placement grid change when rotated 90 degrees
1 messages · Page 1 of 1 (latest)
replace your SnapToGrid function with this
``local function SnapToGrid(pos, blockSize, rotationY)
local angle = (math.floor((rotationY % 360) / 90)) % 4
local gridX, gridZ = blockSize.X, blockSize.Z
-- Swap X and Z grid when rotated 90 or 270 degrees
if angle == 1 or angle == 3 then
gridX, gridZ = blockSize.Z, blockSize.X
end
return Vector3.new(
math.floor(pos.X / gridX + 0.5) * gridX,
math.floor(pos.Y / blockSize.Y + 0.5) * blockSize.Y,
math.floor(pos.Z / gridZ + 0.5) * gridZ
)
end``
and also update ur render
Hm?
RunService.RenderStepped:Connect(function() if mouse.Hit then local snapped = SnapToGrid(mouse.Hit.Position, part.Size, orientation.Y) part.CFrame = CFrame.new(snapped + Vector3.new(0, part.Size.Y / 2, 0)) part.Orientation = orientation end end)
this
ah mb im slow
update your render step like this
np
i updated both and its still the same 😿
is it a local script?
yeah its supposed to be a ghost block or whatever ud call it
is it in ServerPlayerScripts?
it needs to be in StarterPlayerScripts
aight vro
``local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local mouse = plr:GetMouse()
local BuildEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("Build")
local gridSize = 4
local preview = Instance.new("Part")
preview.Anchored = true
preview.CanCollide = false
preview.CanQuery = false
preview.Material = Enum.Material.Brick
preview.Color = Color3.fromRGB(255, 255, 255)
preview.Transparency = 0.5
preview.Size = Vector3.new(3, 5, 7)
preview.Parent = workspace
local orientation = Vector3.new(0, 0, 0)
local function SnapToGrid(pos, blockSize, rotationY)
local angle = (math.floor((rotationY % 360) / 90)) % 4
local gridX, gridZ = blockSize.X, blockSize.Z
if angle == 1 or angle == 3 then
gridX, gridZ = blockSize.Z, blockSize.X
end
return Vector3.new(
math.floor(pos.X / gridX + 0.5) * gridX,
math.floor(pos.Y / blockSize.Y + 0.5) * blockSize.Y,
math.floor(pos.Z / gridZ + 0.5) * gridZ
)
end
RunService.RenderStepped:Connect(function()
if mouse.Hit then
local snapped = SnapToGrid(mouse.Hit.Position, preview.Size, orientation.Y)
preview.CFrame = CFrame.new(snapped + Vector3.new(0, preview.Size.Y / 2, 0))
preview.Orientation = orientation
end
end)
mouse.Button1Down:Connect(function()
local data = {
Position = preview.Position,
Size = preview.Size,
Color = preview.Color,
Material = preview.Material.Name,
Orientation = preview.Orientation,
}
BuildEvent:FireServer(data)
end)
mouse.Button2Down:Connect(function()
orientation = orientation + Vector3.new(0, 90, 0)
if orientation.Y >= 360 then
orientation = Vector3.new(0, 0, 0)
end
end)``
** You are now Level 1! **
try this
nope D:
its aight i just removed the grid and it looked better anyway so cus i kinda suck at this si asked ai to tweak it a bit and now its fine, doesnt lock to grid but it doesnt really have to so im good, thanks.
ohh so u want a rotating thingy
yup