I already have the moving part of the script but now I need to make the part snap to grid which the part in this case target:

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local target = nil
local down = nil
local plr = game.Players.LocalPlayer

function gettarget()
	if mouse.Target ~= nil then
		if mouse.Target.Parent == game.Workspace[plr.Name .. "w"] then
			target = mouse.Target
			mouse.TargetFilter = target
			down = true
		end
	end
end
mouse.Button1Down:connect(gettarget)

function move()
	if down == true then
		if target ~= nil then
			local PosX,PosY,PosZ = mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z
			target.Position = Vector3.new(PosX,PosY,PosZ)
		end
	end
end
mouse.Move:connect(move)

function releasetarget()
	down = false
	target = nil
	mouse.TargetFilter = nil
end
mouse.Button1Up:connect(releasetarget)

Also could you please explain to me how the snapping works?

2 comments

0

welp.. nvm already found it. XD

0

gonna remove since you already found