You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to call a function, where that function I am calling is below my function.
What is the issue? Include screenshots / videos if possible!
local Gui = function()
-- Code here
timeLimit() -- It errors here
end
local startRound = function()
-- Code here
Gui()
end ```
local timeLimit = function()
-- Code here
startRound()
end
game.Players.PlayerAdded:Connect(startRound)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I couldn’t find one that has a similar questions to mine, or maybe I could not find it.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
function checkSight()
follow() --I can call the function since it is below this function
end
function follow()
checkSight() -- It errors, and I can't call the function since It is above?
--Is there anyway I can call a function which that function I am calling has to be below?
end
In my script there are many functions. I want to call one function from the other, but the problem is that the function which will be calling another function is above the function it will be calling, and not below it so it is giving me errors. You might be saying to switch the places, but in my script there are a lot of functions, and if I switch the places of the functions then the other functions will have the same problem! Please tell me how I can make this work.
They are functions it don’t matter the order you place them in the script other than they need to be defined before you call them. So just move it up over the one calling it …
local Gui
local startRound
local timeLimit
Gui = function()
-- Code here
timeLimit() -- It errors here
end
startRound = function()
-- Code here
Gui()
end ```
timeLimit = function()
-- Code here
startRound()
end
game.Players.PlayerAdded:Connect(startRound)
As long as you don’t call before definition (This):
local Gui
local startRound
local timeLimit
Gui = function()
-- Code here
timeLimit() -- It errors here
end
Gui() --Here I am calling before they are defined
startRound = function()
-- Code here
end
timeLimit = function()
-- Code here
startRound()
end
Then there is no problem. For example this is completely fine:
local Gui
local startRound
local timeLimit
Gui = function()
-- Code here
timeLimit()
end
startRound = function()
-- Code here
end
timeLimit = function()
-- Code here
startRound()
end
Gui() --This is fine since it is being called after the 3 functions were defined