Issues with using handleAdornements for grid and movement system script

I’m using handleAdornments for the first time, and I wanted to use them for my building system in my game as I’m still a fairly new developer.

local rs = game:GetService("ReplicatedStorage")

local function checkHandles()
	local player = game.Players.LocalPlayer
	local gui = player:WaitForChild("PlayerGui")

	while true do
		local handlesList = gui:GetChildren() 

		local foundHandles = false

		for _, handles in ipairs(handlesList) do
			if handles.Name == "Handles" then
				foundHandles = true
				local newPos
				
				local function snapToGrid(pos, distance)
					return Vector3.new(
						math.floor((pos.X/4+0.5) *1),
						pos.Y,
						math.floor((pos.Z/4+0.5) *1)
					)
				end
				
				handles.MouseDrag:Connect(function(face, distance)
					local part = handles.Adornee
					print(distance)
					
					if face == Enum.NormalId.Back then
						newPos = part.Position + Vector3.new(0,0,distance)
						part.Position = snapToGrid(newPos)
					elseif face == Enum.NormalId.Front then
						newPos = part.Position + Vector3.new(0,0,-distance)
						part.Position = snapToGrid(newPos)				
					elseif face == Enum.NormalId.Bottom then
						newPos = part.Position + Vector3.new(0,-distance,0)
						part.Position = snapToGrid(newPos)
					elseif face == Enum.NormalId.Right then
						newPos = part.Position + Vector3.new(distance,0,0)
						part.Position = snapToGrid(newPos)
					elseif face == Enum.NormalId.Left then
						newPos = part.Position + Vector3.new(-distance,0,0)
						part.Position = snapToGrid(newPos)
					elseif face == Enum.NormalId.Top then
						newPos = part.Position + Vector3.new(0,distance,0)
						part.Position = snapToGrid(newPos)
					end
				end)
				
				wait(0.1)
			end
		end

		if not foundHandles then
			warn("Handles not found")
		end

		wait(0.1) 
	end
end

checkHandles()

Basically, I saw in the Roblox API that the handleAdornments need to be parented to the PlayerGui for them to be interactive. So, that’s what I did in another script. Then i saw in another post someone showcasing a way to test the handles movement even tho its not optimised which is why my script is not working well, he said that he copied it from a plugin called SBS but i can’t find any link towards that certain plugin and that post is almost 4 years old already, and for some reason in the internet there is little info about how those handles work and how to use them, if anyone knows what plugin they are talking about or if im doing something wrong in my script please let me know.

I appreciate any help given.

Note, i used a while loop because the handles arent there right at the start and they disappear/re-appear from time to time so i made a loop to continuously check if they exist or not

I’ve tried working with HandleAdornments and well unless you worded your initial post incorrectly, you can just put the HandleAdornments in StarterGui in the explorer and just disable them until you need them.

I just made a basic script for them. No grid snapping, nothing so yeah.

(I know this doesn’t really answer the main question but I’ll just add this here)

1 Like