I wish to make a function to easily tween GUI (In a table) offscreen in a modulescript
When trying to get the position of “v” I can print the position however it then immediately errors saying that position is not a valid member of moduleScript
I’ve tried making the position a variable and have checked if it is the print erroring
The code I’m using puts the table I send through a for loop and then tweens all the items in the table, the following is the code that is erroring:
for i,v in pairs(GUITable) do
print(v.Position) --This will print the position and then instantly errors with the above error
v:TweenPosition((position-UDim2.new(0,0,1,0)),dir)
end
Seems like some of the values are other Instances (here, ModuleScript) not related to GuiObject.
for i,v in pairs(GUITable) do
print(v.ClassName) -- ClassName?
print(v.Position) --This will print the position and then instantly errors with the above error
v:TweenPosition((position-UDim2.new(0,0,1,0)),dir)
end
On top of this, you should also try and make sure that “v” is a frame, button, or other UI that can be tweened. The error saying that it can’t get the position of the ModuleScript means the ModuleScript is being included in the for-loop. If you try filtering the names or ClassNames to only tween if it’s a UI object OR not a script or other non UI then it should work better.
You can use Instance:IsA(class_name):
This will return true if given instance inherits class_name (in this case, anything that inherits GuiObject (i.e. Frame, TextBox…))
for i,v in pairs(GUITable) do
if v:IsA("GuiObject") then
v:TweenPosition((position-UDim2.new(0,0,1,0)),dir)
else
-- code when v isn't guiobject
end
end