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.
01 | game:GetService( 'RunService' ).Heartbeat:Connect( function () |
02 | if not deleting then --Activates if the user clicks the delete button, so it can stop rotating and repositioning. |
03 | pcall ( function () |
04 | layout.Parent = script.Parent |
05 | end ) |
06 | for i, v in pairs (items) do |
07 | v.BackgroundColor 3 = Color 3. fromRGB( 255 , 255 , 255 ) |
08 | v.TextColor 3 = Color 3. fromRGB( 27 , 42 , 53 ) |
09 | end |
10 | script:Clone().Parent = script.Parent |
11 | script:Destroy() |
12 | end |
13 |
14 | if order = = 'Asending' then |
15 | position = position + . 5 |
Remember, all of the variables are defined. "Items" is a table full of the buttons that the user can delete. Any idea?
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
.
Edit:
01 | if order = = "Asending" then |
02 | position = position + . 5 |
03 | for i, v in pairs (items) do |
04 | v.Rotation = v.Rotation + 4 |
05 | local XOffSet = v.Position.X.Offset |
06 | local YOffSet = v.Position.Y.Offset |
07 | local X = v.Position.X |
08 | local Y = v.Position.Y |
09 | local FinalOffset = YOffSet + position |
10 | v.Position = UDim 2. new(X + 0.01 , 0 , Y, 0 ) |
11 | wait() |
12 | v.Position = UDim 2. new(X - 0.01 , 0 , Y, 0 ) |
13 | wait() |
14 | v.Position = UDim 2. new(X + 0.01 , 0 , Y, 0 ) |
15 | wait() |
Your script doesn't make much sense of what you want it to do. Fixed original script:
01 | if order = = "Asending" then |
02 | position = position + . 5 |
03 | for i, v in pairs (items) do |
04 | v.Rotation = v.Rotation + 4 |
05 | local XOffSet = v.Position.X.Offset |
06 | local YOffSet = v.Position.Y.Offset |
07 | local X = v.Position.X |
08 | local Y = v.Position.Y |
09 | local FinalOffset = YOffSet + position |
10 | v.Position = UDim 2. new(X, XOffSet, Y, FinalOffSet) |
11 | end |
However, using TweenGui, it will work better.
01 | if order = = "Asending" then |
02 | position = position + . 5 |
03 | for i, v in pairs (items) do |
04 | v.Rotation = v.Rotation + 4 |
05 | local XOffSet = v.Position.X.Offset |
06 | local YOffSet = v.Position.Y.Offset |
07 | local X = v.Position.X |
08 | local Y = v.Position.Y |
09 | local FinalOffset = YOffSet + position |
10 | v:TweenPosition(UDim 2. new(X, XOffSet, Y, FinalOffSet), "Out" , "Quad" , 1 ) |
11 | end |
This will smoothly move the Gui.