How would I make a placement system?

disclaimer: the title is a little misleading - it’s not exactly a placement system I need, but it’s the closest thing

Hello everyone,

There’s many videos of people making placement systems, but what I need is something a little more niche - essentially, I need the player to be able to use their mouse to move a passport, for the passport to snap to the position of a detector part once it is nearby, and for the player to be able to place the passport there only if it’s snapped.

I have a basic placement system script - you can see I attempted to do the above.

local PosX, PosY, PosZ
local Grid = 0.1
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local Part = game.ReplicatedStorage.Part

local isSnapped = false

local function Move()
	if isSnapped then return end
	
	Part.Parent = game.Workspace
	mouse.TargetFilter = Part
	
	PosX = mouse.Hit.X
	PosY = workspace:WaitForChild("detect").Position.Y
	PosZ = mouse.Hit.Z
	
	Part.CFrame = (CFrame.new(PosX, PosY, PosZ))
end

Part.Touched:Connect(function(x)	
	if x.Name == "detect" then
		Part.Position = x.Position
		
		isSnapped = true
	end
end)

mouse.Move:Connect(Move)

mouse.Button1Down:Connect(function()
	if not isSnapped then return end
	
	local newpart = Part:Clone()
	newpart.Parent = game.Workspace
	newpart:SetPrimaryPartCFrame(Part.Base.CFrame)
end)

However, the part does not snap when it touches the detection part.

So, I need to know:

  • How do I make the part snap,
  • How do I restrict the movement of the part so it’s only in the range of the detection part, and
  • How do I make the part “place down”?

Any help is appreciated. Thanks!