Draggable Gui not doing something I want

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    A computer with movable windows.
  2. What is the issue? Include screenshots / videos if possible!
    The windows move around and you can drag them but when you drag them they do not become the window in front, it will stay behind a different one. (photo)

Notice how, even if you are dragging the window around it will always stay under the Appstore window, I want it so the one your dragging stays on top.
3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Good ol’ trouble shooting

Local script in the gui’s frames.


local UIS = game:GetService('UserInputService')
local frame = script.Parent
local dragToggle = nil
local dragSpeed = 0.25
local dragStart = nil
local startPos = nil

local function updateInput(input)
	local delta = input.Position - dragStart
	local position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X,
		startPos.Y.Scale, startPos.Y.Offset + delta.Y)
	game:GetService('TweenService'):Create(frame, TweenInfo.new(dragSpeed), {Position = position}):Play()
end

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

UIS.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
		if dragToggle then
			updateInput(input)
		end
	end
end)

frame:GetPropertyChangedSignal("Visible"):Connect(function()
	if not frame.Visible then
		game:GetService('TweenService'):Create(frame, TweenInfo.new(dragSpeed), {Position = UDim2.new(0.506, 0,0.214, 0)}):Play() --position it returns to.
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

3 Likes

Could you not just in the script in the mouse function also make the Zindex of the Ui being dragged 10 so it is on top of everything?

3 Likes

Im not stupid, im new I swear lol.

1 Like

No worries, glad i was able to help lol.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.