Udim2 incorrectly positioning Gui

This Udim2 script is meant to position a script off the screen so it gives the play more
room to play the game while still being visible where the player can grab the Gui with their cursor and reposition it themselves.

The script works correctly the first time but resets it position back to (0.5, 0, 0.5, 0)
when the button is clicked again.

I attempted to debug the code by adding an if statement to remove the repositioning bug so if its already off screen then it just goes back to the middle of the screen. Knowing my luck and skill of code, this did not work.

If anyone could help me out then it would be greatly appreaciated!

local Button = script.Parent
local PlayerGui = game.Players.LocalPlayer.PlayerGui

Button.MouseButton1Down:Connect(function()
	if PlayerGui.MacScreen.Main.Position == (1.2, 1.29) then
		PlayerGui.MacScreen.Main.Position = UDim2.new(0.5, 0, 0.5, 0)
	else
		PlayerGui.MacScreen.Main.Position = UDim2.new(1.2, 0, 1.29, 0)
	end
end)

-- Was also wondering if they completely removed the Gui Emulator from studio?

image

A Screenshot of the code if it helps.

Are there any errors in the console/output?

The code can’t run at the moment. It errors incorrect syntax.

Does it tell you which line is causing the error?

1 Like

Line 5 since the parameters are incorrect

Okay, could you show me the position for the gui where you want it to go in a screen shot showing the properties tab?

Try this:

local Button = script.Parent
local PlayerGui = game.Players.LocalPlayer.PlayerGui

Button.MouseButton1Down:Connect(function()
	if PlayerGui.MacScreen.Main.Position == UDim2.new(1.2, 0, 1.29, 0) then
		PlayerGui.MacScreen.Main.Position = UDim2.new(0.5, 0, 0.5, 0)
	else
		PlayerGui.MacScreen.Main.Position = UDim2.new(1.2, 0, 1.29, 0)
	end
end)

I believe that is the solution!

1 Like