Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why do I get the error "'for' initial value must be a number" ?

Hey, I'm making a round script and I'm using a ModuleScript to store all of the settings. This is what it looks like:

local Settings = {}
	Intermission = 15;
	GameTime = 60;
		
		
		
		
		
return Settings

This script is inside the main game script. I created variables in the main script to access these values.

--[ Game Variables
Intermission = Settings.Intermission
GameTime = Settings.GameTime 

I did it for the actual script too ;P


--[ Modules
Settings = require(script.Settings)

And I used it for the intermission like this:

if game.Players.NumPlayers >= 1 then
		for i = Intermission, 0, -1 do
			ChangeText("Intermission: " .. i)
			wait(1)
		end

And I get this error

Workspace.CoreGame:46: 'for' initial value must be a number

If I remove the Intermission after for i = and replace it with an actual number it works fine. But I want to have it connect to the settings module script

1 answer

✓ Accepted answer

The reason is that you are not putting Intermission and GameTime in the module script. To put a variable in a module script, you would do

local Settings = {}
Settings.Intermission = 15;
Settings.GameTime = 60;

return Settings

Your script should work then.

Hope this helps!

3 comments

0

I'll try it tahnk you.

0

Also, main scripts like the round scripts should be in ServerScriptService. Clients cannot see them so they can't steal your hard work, and they have the amount of work or whatever they are doing in the dev console.

0

Okay

This discussion is preserved as it was. New answers, comments, and votes are closed.