Pretty self-explanatory but what am I trying to do is make an ImageLabel come visible (by tweening) and after 5.5 seconds another random ImageLabel will be chosen and will repeat the exact same thing.
But after tweening 1 or 2 times it throws out an error saying
Players.AridFights1.PlayerGui.MenuGui.MainMenu:101: invalid argument #2 to 'random' (interval is empty) - Client - MainMenu:101
Script
while task.wait(5.5) do
local GotChildren = Menu_GFX:GetChildren()
local ChosenGFX = GotChildren[math.random(1, #GotChildren)]
ChosenGFX:Clone().Parent = GFXHolder
local Info = TweenInfo.new(1)
local function Tween(obj, trans)
local t = TweenService:Create(obj, Info, {ImageTransparency = trans})
return t
end
Tween(ChosenGFX, 0)
task.wait(5.5)
local ChosenGFX_2 = GotChildren[math.random(1, #GotChildren)]
ChosenGFX_2:Clone().Parent = GFXHolder
task.spawn(function()
Tween(ChosenGFX_2, 0)
Tween(ChosenGFX, 1)
end)
task.wait(0.5)
ChosenGFX:Destroy()
task.wait(5.5)
ChosenGFX_2:Destroy()
end
local ChosenGFX = GotChildren[math.random(1, #GotChildren)]
ChosenGFX:Clone().Parent = GFXHolder
Here you are selecting a ChosenGFX, creating a clone, and adding the clone to GFXHolder. The issue is, you are not referencing the clone, you are referencing the original ChosenGFX. So when you:
ChosenGFX:Destroy()
You are deleting the original GFX. As you loop, you eventually run out of GFX because you’ve destroyed them all. This makes GotChildren an empty table, hence your error.
local list = script.Parent:GetChildren()
local random = math.random(1,#list)
for i = 1, random do
part = list[i]
if i == random then
local model = part
local clone = model:Clone()
clone.Parent = part.Parent--you can put this to whever you want
end
end
Well, that fixed the choosing problem, but the tweening doesn’t work. Here’s the updated code:
while task.wait(5.5) do
local GotChildren = Menu_GFX:GetChildren()
local ChosenGFX = GotChildren[math.random(1, #GotChildren)]
local Clone = ChosenGFX:Clone()
Clone.Parent = GFXHolder
local Info = TweenInfo.new(1)
local function Tween(obj, trans)
local t = TweenService:Create(obj, Info, {ImageTransparency = trans})
return t
end
Tween(ChosenGFX, 0):Play()
task.wait(5.5)
local ChosenGFX_2 = GotChildren[math.random(1, #GotChildren)]
local Clone_2 = ChosenGFX_2:Clone()
Clone_2.Parent = GFXHolder
task.spawn(function()
Tween(ChosenGFX_2, 0):Play()
Tween(ChosenGFX, 1):Play()
end)
task.wait(0.5)
Clone:Destroy()
task.wait(5.5)
Clone_2:Destroy()
end