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

How to move a gui using a script?

Im trying to move a frame when clicked, but I get an error

function click()
	print(script.Parent.Parent)
	if script.Parent.Parent.Position.X == UDim.new(1, -45) then
	print("ok")
	script.Parent.Parent.Position.X = UDim.new(1, -150)
	elseif script.Parent.Parent.Position.X == UDim.new(1, -150) then
	script.Parent.Parent.Position.X = UDim.new(1, -45)
	end
	end
script.Parent.MouseButton1Click:connect(click)

Output: "Menu", "ok", "10:22:48.229 - X cannot be assigned to"

1 answer

✓ Accepted answer

You can't set the properties of UDim2s (they are immutable, like numbers or strings).

You have to set the whole UDim2 instead:

gui.Position = UDim2.new( 1, -150, gui.Position.Y.Scale, gui.Position.Y.Offset )

(You use script.Parent.Parent 5 times in this script -- it should definitely be a variable)


I would recommend you don't actually compare the position to determine where it is. If you decided you want to move it, that would become a pain. Use variables to say where it is (where = "on" or where = "left" or other descriptive values)

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