Currently, I have my system to where you can place parts anywhere but I would like it to where there's a grid and it snaps onto something so you can't just place it freely anywhere. How would you go by doing that? I don't know how to do that.
Here is my script currently and it works fine, I'm not requesting a script. I'm asking on how you would go by making this into a grid placement system.
I'm not sure if this is efficient either so if you could tell me how to make this more efficient that would help :D
--<< Variables
local Players = game:GetService('Players')
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local currentlyBuilding = false
local addVector = Vector3.new(0, 0.5, 0)
--// Main
script.Parent.Activated:Connect(function()
if not currentlyBuilding then
currentlyBuilding = true
local viewPart = Instance.new('Part')
viewPart.Name = player.Name.."'s ViewPart"
viewPart.Parent = workspace
viewPart.CanCollide = false
viewPart.Transparency = 0.7
viewPart.Anchored = true
mouse.TargetFilter = viewPart
mouse.Move:Connect(function()
while currentlyBuilding do
wait()
viewPart.Position = mouse.Hit.p + addVector
end
end)
mouse.Button1Down:Connect(function()
local position = mouse.Hit.p
local createPart = viewPart:Clone()
createPart.Parent = workspace
createPart.Position = position + addVector
createPart.Transparency = 0
createPart.CanCollide = false
end)
else
currentlyBuilding = false
local viewPart = workspace:FindFirstChild(player.Name.."'s ViewPart"):Destroy()
end
end)

1 comment
In line 12, assuming the Activated event belongs to a Tool (TextButton’s have this event), The Activated event of a Tool has the same behaviour as the Button1Down event. You should maybe remove the button1down event and just have your code in that event belong to the activated one.