01 | local Core = require(game.Workspace.Music.Core) |
02 |
03 | while 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 |
19 | end |
Module Script named Core:
1 | local Core = { } |
2 |
3 | function Change() |
4 | game.Workspace.Music.MainText.Value = game.Workspace.Music.MusicName.Value |
5 | end |
6 |
7 | return Core |
Why won't this script work it keeps on saying Nil Value on Core.Change()
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:
1 | function Core.Change() |
2 | -- ... |
3 | end |
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:
01 | local 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:
01 | local Core = { } |
02 |
03 | local function Change() |
04 | -- ... |
05 | end |
06 |
07 |
08 | Core [ "Change" ] = Change |
09 |
10 | -- Or, without square brackets: |
11 | Core.Change = Change |