Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I go about controllable GUIs?

While this isn't a direct coding error, I'm wondering how I would go about scripting controllable GUIs (By that I mean, a little blob one could move around on screen). This is for my little project of building a retro arcade machine inside of ROBLOX. I have a reasonable amount of experience/knowledge when it comes to Lua programming. Thanks in advance :)

2 comments

0

you can just do gui.Draggable = true, and this is really vague.

0

The Draggable Property has been deprecated.

2 answers

✓ Accepted answer

You can place this inside s local script inside the Gui Object you wish to move:

local UserInputService = game:GetService("UserInputService")

local gui = script.Parent

local dragging
local dragInput
local dragStart
local startPos

local function update(input)
	local delta = input.Position - dragStart
	gui.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
end

gui.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		dragging = true
		dragStart = input.Position
		startPos = gui.Position
		
		input.Changed:Connect(function()
			if input.UserInputState == Enum.UserInputState.End then
				dragging = false
			end
		end)
	end
end)

gui.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
		dragInput = input
	end
end)

UserInputService.InputChanged:Connect(function(input)
	if input == dragInput and dragging then
		update(input)
	end
end)

Too much to explain to be honest.

Hope this helps. :)

1 comment

0

awesome, thanks a lot :)

just listen for input events.. like maybe if a key is pressed or a finger is slid on the screen, you move the GUI in a particular direction, and things like that..

This discussion is preserved as it was. New answers, comments, and votes are closed.