Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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!

0
I'll try it tahnk you. PixelZombieX 8 — 6y
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. hiimgoodpack 2009 — 6y
0
Okay PixelZombieX 8 — 6y
Ad

Answer this question