Didn’t want to waste anyone’s time by reading irrelevant code but here’s the entire script:
--// items //--
local StartGameEvent = game.ReplicatedStorage:WaitForChild("StartGame")
local CountdownEvent = game.ReplicatedStorage:WaitForChild("CountdownShown")
--// Functions //--
local function CountdownFrom(Number)
CountdownEvent:FireAllClients(Number)
wait(Number)
end
--// Start Game //--
StartGameEvent.OnServerEvent:Connect(function(Amount, TrueOrFalse)
CountdownFrom(15)
end)
Can you share an example of where the use of ‘local’ causes a script to break?
From the linked article.
Local variables are obtained faster than global variables because they’re integrated into the environment in which they were created. If possible, you should always use local variables over global variables, unless there’s a specific reason otherwise.
i dont think its needed and it may block it because its in a function from where its being executed
yes it does because its local it only does things after line
or are mostly kept in functions not for functions
Your understanding of the word ‘block’ is different from mine, ‘local’ variables/functions can only be referenced from after they are initially declared/defined respectively due to the lexical (in order) scoping rules Lua uses.
cannot since i have already edited them and i would not remember which one it was
but it doesnt mean it did not break because of that
This is likely an issue with your code as opposed to the ‘local’ keyword itself.
Variables can have global or local scopes. They have global scope by default, but it’s almost always better to create them with local scope because Luau accesses local variables faster than global ones. To give a variable local scope, put the keyword local before a variable’s name when you assign a value to it. For more information on Scope in Luau, see Scope.
yes it does because its local it only does things after line
--// Functions //--
local function CountdownFrom(Number)
CountdownEvent:FireAllClients(Number)
wait(Number)
end
--// Start Game //--
StartGameEvent.OnServerEvent:Connect(function(Amount, TrueOrFalse)
CountdownFrom(15)
end)
Your assertion here is incorrect, the function is defined locally before it is called.
It is good programming style to use local variables whenever possible. Local variables help you avoid cluttering the global environment with unnecessary names. Moreover, the access to local variables is faster than to global ones.
There is no reason on why it should Not be used
unless its in a function which there comes the local use
another one as i said
this should be used if it doesnt error and in most cases should be put Globals at the start
and only in functions the locals
i never said locals cant be at the start
but globals are better at doing that Conclusion:
the sites you are sending me are saying the same thing
the first being the legacy version of roblox
the second being a reworked site
and the third being a general lua site
and all of them are saying the exact thing
so how do you call 3 diffrent sites that say the same thing official since its only 1