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

How do I move a GUI by clicking on another GUI?

I made 2 frames under a ScreenGui with different positions. One frame has a ButtonGui and the other does not. I put a script in the ButtonGui so that it would move the other frame to the same position as the one with the ButtonGui.

THING is the screen Gui, moving is the frame i'm trying to move, and ayy is the frame with the ButtonGui

this is the script:

script.Parent.MouseButton1Down:Connect(function()
	local gui=game.StarterGui.THING
	
	gui.Moving.Position=gui.ayy.Position
end)

1 comment

0

Hope I can help!

2 answers

You didn't use UDim2.new() for moving frames. If you want to make it glide to that position you can use :TweenPosition(). U also failed by using the ScreenGui, you needed to use instead PlayerGui, you also need to use MouseButton1Click. I am going to add the example on your code for all the ways. This will work with FE and without FE enabled.

Code without gliding:

local plr = game:GetService("Players").LocalPlayer -- It's not necessary to use :GetService().
local gui = plr.PlayerGui:WaitForChild("THING") -- Added wait for child to improve script performance.

script.Parent.MouseButton1Click:Connect(function()
    gui.Moving.Position = UDim2.new(gui.ayy.Position)
end)

Code with gliding:

local plr = game:GetService("Players").LocalPlayer -- It's not necessary to use :GetService().
local gui = plr.PlayerGui:WaitForChild("THING") -- Added wait for child to improve script performance.

script.Parent.MouseButton1Click:Connect(function()
	-- Make sure to put the Moving gui down below of the position of the frame to be moved.
	gui.Moving:TweenPosition(UDim2.new(gui.ayy.Position), "Out", 4)
	wait(1)
end)


local gui = game.StarterGui.THING

script.Parent.MouseButton1Click:Connect(function()
      gui.Moving.Position = UDim2.new(gui.ayy.Position)
end)

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