What is wrong here?

Error: “Incomplete statement: expected assignment or a function call”

Server Script:

local function CountdownFrom(Number)
	CountdownEvent:FireAllClients(Number)
	wait(Number)
end

CountdownFrom(15)

Local Script:

local ItTag = game.ReplicatedStorage:WaitForChild("It")
local Countdown = game.Players.LocalPlayer.PlayerGui:WaitForChild("Timer").Countdown
local CountdownEvent = game.ReplicatedStorage:WaitForChild("CountdownShown")

CountdownEvent.OnClientEvent:Connect(function(Number)
	Countdown:TweenPosition(UDim2.new(0, 0, 0, 0),
		"Out",
		"Back",
		0.3
)
	
	local start = os.clock()
	local CurrentTime = Number
	while os.clock() - start <= CurrentTime do   
		game:GetService("RunService").Heartbeat:Wait()

		local timeLeft = math.max((CurrentTime - (os.clock() - start)), 0)
		local Minutes = math.floor(timeLeft / 60)
		timeLeft = timeLeft - (Minutes * 60)
		local Seconds = math.floor(timeLeft)
		local Milliseconds = math.floor((timeLeft - Seconds) * 1000)

		timeLeft = string.format("%d.%.03d", Seconds, Milliseconds)
		Countdown.Text = "Starting In: "..string.format("%d.%.03d", Seconds, Milliseconds)
end	
		Countdown:TweenPosition(UDim2.new(0, 0, -0.5, 0),
			"In",
			"Quad",
			1
		)

end)

Does the error say what line is it or what is the context of the script?

1 Like

The line where it says “CountdownFrom(15)” and it’s in the server script.

Is it the whole script? the error may be because you used == instead of =.

2 Likes

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)

maybe remove the local?
i dont think its needed and it may block it because its in a function from where its being executed

dont forget to add a player instance before the custom values
(function(Player,Amount, TrueOrFalse)
just in case you changed it

1 Like
StartGameEvent.OnServerEvent:Connect(function(Amount, TrueOrFalse)
	CountdownFrom(15)
end)

You forgot the player object that’s passed when FireServer is called on a ‘RemoteEvent’ object.

1 Like

The ‘local’ keyword is fine, in fact it should be used when defining functions/declaring variables.

1 Like

not really i have found many scripts where the local variable just breaks it all
so its more suggested not using locals at a start

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

The use of ‘local’ doesn’t block anything.

1 Like

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

yes it does because its local it only does things after line
or are mostly kept in functions not for functions

that is indeed one of the reasons
it doesnt error always but it can based on how you use it

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.

1 Like

a block means a error comes into the output and stops the whole script
basic words blocking the script
unless its in the function.

this is likely not only my script that had this error but multiple but people odly fix this if they know how to use it correctly.

a block means a error comes into the output and stops the whole script

No, an error is an error, errors terminate the stack (not block). The use of ‘local’ will never cause errors (unless used incorrectly).

this is likely not only my script that had this error but multiple but people odly fix this if they know how to use it correctly.

You’re arguing a moot point, globals should never be used, they don’t need to be used.

https://create.roblox.com/docs/scripting/luau/variables

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.

You’re disputing two official Roblox sources.

1 Like

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.

1 Like

i dont really have a problem as how you call it

odly false information without globals the script would just not work based on how you used locals

cool but roblox even says it that it should be both used (from what you have sent me).

functions are not meant to be local unless a function is Inside a function
but i dont see a reason why you should do that

cool its at the start thats why it probably wont error
but in most cases if its at the start its suggested to be a global function

Suggested where? I’ve provided two official sources for my claims, all you’ve provided is questionable anecdotal evidence.

Here’s a third.
https://www.lua.org/pil/4.2.html

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.

1 Like

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