So I have a script that does some stuff but it needs to get something from a function in a module.
Only problem is that it doesnt wait for the function to return, the second the function is triggered it instantly before I even call return, why? And how can I make it actually work?
Main script:
-- main code
AnimateButton.Click:Connect(function()
gui.Enabled = not gui.Enabled
if gui.Enabled then
if not last then
local anims = control.StartUp() -- this is the thing that returns nil
warn(anims)
if anims then
control.Animator(anims)
end
else -- pickup after where we left off
end
end
end)
Functions
module.StartUp = function()
warn('called')
gui.Parent = c
for _, frame in pairs(gui:GetChildren()) do
if frame:IsA('GuiObject') then
frame.Visible = false
end
end
local currentFrame = gui:FindFirstChild('SelectRigs')
currentFrame.Visible = true
currentFrame:FindFirstChild('Confirm').Activated:Once(function()
local rigs = module.Functions.GetSelected()
local anims = nil
local total = #rigs
local allDone = 0
warn(total)
if rigs[1] then
for _, rig:Model in pairs(rigs) do
currentFrame.Visible = false
local done = false
currentFrame = gui:FindFirstChild('CreateOrPast')
currentFrame:FindFirstChild('Desc').Text = 'WOULD YOU LIKE TO CREATE A NEW ANIMATION OR LOAD ONE FOR '..string.upper(rig.Name)..'?'
currentFrame.Visible = true
currentFrame:FindFirstChild('Create'):FindFirstChildOfClass('TextButton').Activated:Once(function() -- create a new one
currentFrame.Visible = false
currentFrame = gui:FindFirstChild('Create')
currentFrame.Visible = true
currentFrame:FindFirstChild('Desc').Text = 'CREATE AN ANIMATION FOR '..string.upper(rig.Name)..'!'
local name = ''
local connect = currentFrame:FindFirstChild('Name'):FindFirstChildOfClass('TextBox'):GetPropertyChangedSignal('Text'):Connect(function() -- when the text changes update it-
name = currentFrame:FindFirstChild('Name'):FindFirstChildOfClass('TextBox').Text
end)
currentFrame:FindFirstChild('Confirm').Activated:Connect(function()
if name ~= '' and name ~= ' ' then
currentFrame.Visible = false
connect:Disconnect()
local anim = plug:FindFirstChild('Default'):FindFirstChild('Animation'):Clone()
anim.Name = name
local folder = rig:FindFirstChild('Animations')
if not folder then
folder = Instance.new('Folder')
folder.Name = 'Animations'
folder.Parent = rig
end
anim.Parent = folder
if not anims then
anims = {}
end
anims[rig.Name] = anim
done = true
allDone += 1
else
warn('PLEASE CREATE A NAME FOR THE ANIMATION')
end
end)
end)
repeat task.wait(0.1) until done
warn('Done')
end
wait(1)
repeat until allDone >= total
warn('Done')
return anims
else
warn('NO RIGS')
return
end
end)
currentFrame:FindFirstChild('Cancel').Activated:Once(function()
gui.Enabled = false
warn('cheese')
return
end)
end
also note that I have warn in front of all the returns and none of them print