Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to move a gui using a script?

Asked by 9 years ago

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

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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)

Ad

Answer this question