I think it's this:
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
round(mouse.Hit.Position,3)
or:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local player = Players.LocalPlayer
local block = ReplicatedStorage:WaitForChild("block")
local REACH = 100
mouse.Button2Down:Connect(function()
local unitRay = mouse.UnitRay
local castParams = RaycastParams.new()
castParams.FilterDescendantsInstances = { player.Character }
local result = Workspace:Raycast(
unitRay.Origin, unitRay.Direction * REACH,
castParams
)
if result then
local newBlock = block:Clone()
newBlock.Position = round(result.Position + result.Normal * 1.5, 3)
newBlock.Parent = workspace
end
end)
I'm not really good at scripting.
5 comments
No attempt made to actually translate the position to 3D space?
the reason is because i am very new to coding
"Thank you but how do I place this code can you place a picture please. I have tried and it does not work. But thank you for the help"
i think u put it in serverscriptstorage, basic script
I have a question when I click the mouse does it just place down anywhere or does it need a base?