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?
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:
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.