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

Nil data for a module script?

Asked by
iRexBot 147
8 years ago
01local Core = require(game.Workspace.Music.Core)
02 
03while true do
04    script.Parent.MusicPlayer.Song.Value = math.random(1, 13)
05    wait(st)
06    wait(0.1)
07    print(script.Parent.MusicPlayer.Song.Value)
08    if script.Parent.MusicPlayer.Song.Value == 0 then
09        wait(4)
10        st = 206.513
11        script.Parent.Sound.SoundId = "rbxassetid://419901901"
12        game.Workspace.Music.MusicName.Value = "Alan Walker - Faded (Sep Remix)"
13        Core.Change()
14        script.Parent.Sound:Play()
15        wait(119.98)
16        script.Parent.Sound.SoundId = "rbxassetid://419901917"
17        script.Parent.Sound:Play()
18    end
19end

Module Script named Core:

1local Core = {}
2 
3function Change()
4    game.Workspace.Music.MainText.Value = game.Workspace.Music.MusicName.Value
5end
6 
7return Core

Why won't this script work it keeps on saying Nil Value on Core.Change()

1 answer

Log in to vote
0
Answered by
Link150 1355 Badge of Merit Moderation Voter
8 years ago

This is because you didn't add Change to Core. You defined it as a global variable. You want to insert it into your Core table, otherwise there is no way for the script require()ing the module to retrieve your function back.

There are multiple ways to do this, the best in your case is probably:

1function Core.Change()
2    -- ...
3end

This has the advantage to be easily readable. In the context of a module, anyway.

Another way is to insert them into your table literal:

01local Core = {
02    ["Change"] = function()
03        -- ...
04    end,
05 
06    -- Or, without square brackets:
07    Change = function()
08            -- ...
09    end
10}

but it's not as easily readable.

You could also insert them afterwards:

01local Core = {}
02 
03local function Change()
04    -- ...
05end
06 
07 
08Core["Change"] = Change
09 
10-- Or, without square brackets:
11Core.Change = Change
Ad

Answer this question