Alright, i’ve been experimenting with placement systems in general for months now and they’re pretty easy when u get used to them, first of all u would have to get the Player Mouse by doing player:GetMouse() to find the mouse location obviously, and u would have to use RunService to keep updating the Block Position right? so a quick recapitulation of what we just said.
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local RunService = game:GetService("RunService")
local DummyBlock = game.ReplicatedStorage.Block:Clone(); DummyBlock.Parent = workspace; DummyBlock.Transparency = 0.5; DummyBlock.CanCollide = false
local function roundToStep(initialValue,step)
local roundedValue = math.floor(initialValue/step)*step
return roundedValue --Returns 60
end
RunService.RenderStepped:Connect(function()
DummyBlock.Position = Vector3.new(roundToStep(Mouse.Hit.Position.X, 4), 0, roundToStep(Mouse.Hit.Position.Z, 4))
end)
Mouse.Button1Down:Connect(function()
local Block = game.ReplicatedStorage.Block:Clone(); Block.Parent = workspace
Block.Position = Vector3.new(roundToStep(Mouse.Hit.Position.X, 4), 0, roundToStep(Mouse.Hit.Position.Z, 4))
end)
@xZylter just gave the method and here’s how u could implement it into the script i just gave this would snap the grid to 4 each time u move your mouse,
Although @xZylter i changed math.round to math.floor cause it bugs out when u snap it to 2 different values. Snapping it to math.floor would be a better choice but both still work.
Expanding off of @ReplicaService’s code to change the step to round to you can use this function.
local function roundToStep(initialValue,step) --Let initialValue = 59, step = 10
local roundedValue = math.round(initialValue/step)*step
return roundedValue --Returns 60
end
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local RunService = game:GetService("RunService")
local DummyBlock = game.ReplicatedStorage.Block:Clone(); DummyBlock.Parent = workspace; DummyBlock.Transparency = 0.5; DummyBlock.CanCollide = false
local function roundToStep(initialValue,step)
local roundedValue = math.floor(initialValue/step)*step
return roundedValue --Returns 60
end
RunService.RenderStepped:Connect(function()
DummyBlock.Position = Vector3.new(roundToStep(Mouse.Hit.Position.X, 4), 0, roundToStep(Mouse.Hit.Position.Z, 4))
end)
Mouse.Button1Down:Connect(function()
local Block = game.ReplicatedStorage.Block:Clone(); Block.Parent = workspace
Block.Position = Vector3.new(roundToStep(Mouse.Hit.Position.X, 4), 0, roundToStep(Mouse.Hit.Position.Z, 4))
end)
@xZylter just gave the method and here’s how u could implement it into the script, this would snap the grid to 4 each time u move your mouse,
Although @xZylter i changed math.round to math.floor cause it bugs out when u snap it to 2 different values. Snapping it to math.floor would be a better choice but both still work.
You can use the player’s mouse to do this, use the Mouse.Move event to detect if the player’s mouse has moved and the Mouse.Button1Down event to detect if the player has left clicked.
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local mouse = localPlayer:GetMouse()
local block = Instance.new("Part")
block.Size = Vector3.new(4, 4, 4)
block.CanCollide = false
block.Transparency = .5
block.Parent = workspace
local heightOffset = Vector3.new(0, block.Size.Y / 2, 0)
mouse.Move:Connect(function()
block.Position = mouse.Hit.Position + heightOffset
end)
mouse.Button1Down:Connect(function()
local placedBlock = block:Clone()
placedBlock.Transparency = 0
placedBlock.CanCollide = true
end)
Hey quick question. In order to make it snap to 3 studs instead of 4 would I just replace all the 4s with 3s? I did that but the block was half in the floor. and it kind of bugging out. Sorry for the inconvenience.