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

Cannot change a TextButton's position?

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?

3 comments

0

Read your Bio.

0

its in a localscript...............

0

hiimgoodpack, Don't know what you are trying to do here.

2 answers

✓ Accepted answer

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.

12 comments

0

The offset is not read only, because it is not grayed out.

0

I know, but you still have to use UDim2 to define the Scale and Offset of X and Y.

0

No, it is a property of Position. Under position is X and Y and under those is Scale and Offset.

0

Yeah, and since it is not grayed out, you can edit it.

0

Either way, you have to use Udim2(XScale,XOffset,YScale,YOffset) to change/define the position of an object.

0

why is it read only?

0

What do you mean?

0

Let me edit my answer so It makes more sense.

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.

0

Then set it to UDim2(0,0,0,YOffset)

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?

0

I have no idea.

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.

5 comments

0

This doesnt work for me, because when i used this, it kept going down or up and going off the screen.

0

Do you know have ascending and descending means? I dont just want a one pixel change......

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.

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?"

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.

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