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

Cannot change a TextButton's position?

Asked by 6 years ago

I am making a GUI where you can select and delete stuff. For the deleting part, I want a shaking part. I have already done that. But I want it to like move the button's position, but it errors "Offset cannot be assigned to" whenever I put this in my script.

game:GetService('RunService').Heartbeat:Connect(function()
    if not deleting then --Activates if the user clicks the delete button, so it can stop rotating and repositioning.
        pcall(function()
            layout.Parent = script.Parent
        end)
        for i, v in pairs(items) do
            v.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
            v.TextColor3 = Color3.fromRGB(27, 42, 53)
        end
        script:Clone().Parent = script.Parent
        script:Destroy()
    end

    if order == 'Asending' then
        position = position + .5
        for i, v in pairs(items) do
            v.Rotation = v.Rotation + 4
            v.Position.Y.Offset = v.Position.Y.Offset + position --This is the line that errors.
            print(v.Position.Y.Offset)
        end
        if items[1].Rotation == 20 then
            order = 'Desending'
        end
    elseif order == 'Desending' then
        for i, v in pairs(items) do
            v.Rotation = v.Rotation - 4
        end
        if items[1].Rotation == -20 then
            order = 'Asending'
        end
    end
end)

Remember, all of the variables are defined. "Items" is a table full of the buttons that the user can delete. Any idea?

0
Read your Bio. TinyScripter 70 — 6y
0
its in a localscript............... hiimgoodpack 2009 — 6y
0
hiimgoodpack, Don't know what you are trying to do here. thesit123 509 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You can't just say v.Position.Y.Offset = v.Position.Y.Offset + position, you have to use UDim2, because that's basically saying v.Position.Y.Offset = 0 + {0,0},{0,0}. You need to do this: v.Position = UDim2.new(v.Position) + UDim2.new(position). You cant define Position with just numbers, it has to use UDim2.

0
The offset is not read only, because it is not grayed out. hiimgoodpack 2009 — 6y
0
I know, but you still have to use UDim2 to define the Scale and Offset of X and Y. PyccknnXakep 1225 — 6y
0
No, it is a property of Position. Under position is X and Y and under those is Scale and Offset. hiimgoodpack 2009 — 6y
0
Yeah, and since it is not grayed out, you can edit it. hiimgoodpack 2009 — 6y
View all comments (8 more)
0
Either way, you have to use Udim2(XScale,XOffset,YScale,YOffset) to change/define the position of an object. PyccknnXakep 1225 — 6y
0
why is it read only? hiimgoodpack 2009 — 6y
0
What do you mean? PyccknnXakep 1225 — 6y
0
Let me edit my answer so It makes more sense. PyccknnXakep 1225 — 6y
0
No, because that is not my position. The position is the offset, and it is a number. Otherwise, on line 15, it would error "could not perform arithmetic on a UDim2" or something. hiimgoodpack 2009 — 6y
0
Then set it to UDim2(0,0,0,YOffset) PyccknnXakep 1225 — 6y
0
Oh, just looked up what a UDim is since like i never use it or thought i used it and looked what it was. http://wiki.roblox.com/index.php?title=UDim#Offset . Well, the question is, why is it read only? hiimgoodpack 2009 — 6y
0
I have no idea. PyccknnXakep 1225 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Edit:

if order == "Asending" then
    position = position + .5
    for i, v in pairs(items) do
        v.Rotation = v.Rotation + 4
        local XOffSet = v.Position.X.Offset
        local YOffSet = v.Position.Y.Offset
        local X = v.Position.X
        local Y = v.Position.Y
        local FinalOffset = YOffSet + position
        v.Position = UDim2.new(X + 0.01, 0, Y, 0)
    wait()
    v.Position = UDim2.new(X - 0.01, 0, Y, 0)
    wait()
    v.Position = UDim2.new(X + 0.01, 0, Y, 0)
    wait()
    v.Position = UDim2.new(X - 0.01, 0, Y, 0)
    wait()
    v.Position = UDim2.new(X + 0.01, 0, Y, 0)
    wait()
    v.Position = UDim2.new(X - 0.01, 0, Y, 0)
    wait()
    v.Position = UDim2.new(X + 0.01, 0, Y, 0)
    wait()
    v.Position = UDim2.new(X - 0.01, 0, Y, 0)
    wait()
    end
end

Your script doesn't make much sense of what you want it to do. Fixed original script:

    if order == "Asending" then
        position = position + .5
        for i, v in pairs(items) do
            v.Rotation = v.Rotation + 4
            local XOffSet = v.Position.X.Offset
            local YOffSet = v.Position.Y.Offset
            local X = v.Position.X
            local Y = v.Position.Y
            local FinalOffset = YOffSet + position
            v.Position = UDim2.new(X, XOffSet, Y, FinalOffSet)
        end

However, using TweenGui, it will work better.

if order == "Asending" then
        position = position + .5
        for i, v in pairs(items) do
            v.Rotation = v.Rotation + 4
            local XOffSet = v.Position.X.Offset
            local YOffSet = v.Position.Y.Offset
            local X = v.Position.X
            local Y = v.Position.Y
            local FinalOffset = YOffSet + position
            v:TweenPosition(UDim2.new(X, XOffSet, Y, FinalOffSet), "Out", "Quad", 1)
        end

This will smoothly move the Gui.

0
This doesnt work for me, because when i used this, it kept going down or up and going off the screen. hiimgoodpack 2009 — 6y
0
Do you know have ascending and descending means? I dont just want a one pixel change...... hiimgoodpack 2009 — 6y
0
Your script doesnt even make any sense. None of us even have a clue what you are trying to do. One pixel is very obvious. Offset 1. Please stop downvoting me for stuff you do. TinyScripter 70 — 6y
0
1: Someone else downvoted you, not me. 2: One pixel is NOT very obvious unless your staring at it like "hmmm does this ever change?" hiimgoodpack 2009 — 6y
0
It's quite simple to figure out what he was doing actually. I think everyone should know that changing/setting a position of a GUI object should be defined using UDim2. He also specified what line was erroring, which was really helpful. PyccknnXakep 1225 — 6y

Answer this question