Hello! I am trying to add a tween for a GUI to smoothly open and close. So far, it has gone successful besides the fact that once it gets to the part when it has to make the content in the GUI visible. It tells me “Unable to cast value to Object”. Help would be appreciated. Thanks!
local Panel = script.Parent
local Cooldown = false
local Items = {}
function OpenPanel()
Cooldown = true
Panel.Visible = true
TweenService:Create(Panel,TweenInfo.new(0.5,Enum.EasingStyle.Sine),{Size = PanelSize}):Play()
wait(0.5)
for _, Object in pairs(Items) do
if Object[1]:IsA("Frame") then
TweenService:Create(Object,TweenInfo.new(0.5,Enum.EasingStyle.Sine),{BackgroundTransparency = Object[2]}):Play()
elseif Object:IsA("TextButton") or Object:IsA("TextLabel") or Object:IsA("TextBox") then
TweenService:Create(Object,TweenInfo.new(0.5,Enum.EasingStyle.Sine),{TextTransparency = Object[2],BackgroundTransparency = Object[3]}):Play()
elseif Object:IsA("ScrollingFrame") then
TweenService:Create(Object,TweenInfo.new(0.5,Enum.EasingStyle.Sine),{ScrollBarImageTransparency = Object[2]}):Play()
elseif Object:IsA("ImageLabel") then
TweenService:Create(Object,TweenInfo.new(0.5,Enum.EasingStyle.Sine),{ImageTransparency = Object[2]}):Play()
end
end
wait(0.5)
table.clear(Items)
Cooldown = false
end
you certainly can, my games are covered in stuff like this TS:Create(frame, tweenInfo, {Position = UDim2.new(0.5,0,0.975,0)}):Play()
the UI-exclusive solutions are derivative of TweenService, are redundant in my opinion and should be superseded by TweenService directly. Personally I don’t know why they’ve yet to deprecate TweenPosition.
As I believe you can see, They are in tables, but the actual things themselves are number values on things like the text transparency and background transparency.
I will also share the actual Close function if it helps.
function ClosePanel()
Cooldown = true
for _, Object in pairs(Panel:GetDescendants()) do
if Object:IsA("Frame") then
table.insert(Items,{Object,Object.BackgroundTransparency})
TweenService:Create(Object,TweenInfo.new(0.5,Enum.EasingStyle.Sine),{BackgroundTransparency = 1}):Play()
elseif Object:IsA("TextButton") or Object:IsA("TextLabel") or Object:IsA("TextBox") then
table.insert(Items,{Object,Object.TextTransparency,Object.BackgroundTransparency})
TweenService:Create(Object,TweenInfo.new(0.5,Enum.EasingStyle.Sine),{TextTransparency = 1,BackgroundTransparency = 1}):Play()
elseif Object:IsA("ScrollingFrame") then
table.insert(Items,{Object,Object.ScrollBarImageTransparency})
TweenService:Create(Object,TweenInfo.new(0.5,Enum.EasingStyle.Sine),{ScrollBarImageTransparency = 1}):Play()
elseif Object:IsA("ImageLabel") then
table.insert(Items,{Object,Object.ImageTransparency})
TweenService:Create(Object,TweenInfo.new(0.5,Enum.EasingStyle.Sine),{ImageTransparency = 1}):Play()
end
end
wait(0.5)
TweenService:Create(Panel,TweenInfo.new(0.5,Enum.EasingStyle.Sine),{Size = UDim2.new(0,0,0,0)}):Play()
wait(0.5)
Panel.Visible = false
Cooldown = false
end
I see, you’re using index notation which is what confused me. Only your first conditional (IsA frame) is referencing Object[1], the rest reference the table directly, which will be producing the error you’re calling TweenService on a table. I would recommend moving to dictionary notation for clarity. I’ll reformat your first conditional (frame) in both to show what I mean:
Open
for _, Object in pairs(Items) do
if Object.Instance:IsA("Frame") then
TweenService:Create(Object.Instance, TweenInfo.new(0.5, Enum.EasingStyle.Sine), {BackgroundTransparency = Object.BackgroundTransparency}):Play()
else--[...]
Close
for k, Object in pairs(Panel:GetDescendants()) do
if Object.Instance:IsA("Frame") then
Items[k] = {Instance = Object, BackgroundTransparency = Object.BackgroundTransparency}
TweenService:Create(Object, TweenInfo.new(0.5, Enum.EasingStyle.Sine), {BackgroundTransparency = 1}):Play()
else--[...]