local Core = require(game.Workspace.Music.Core) while true do script.Parent.MusicPlayer.Song.Value = math.random(1, 13) wait(st) wait(0.1) print(script.Parent.MusicPlayer.Song.Value) if script.Parent.MusicPlayer.Song.Value == 0 then wait(4) st = 206.513 script.Parent.Sound.SoundId = "rbxassetid://419901901" game.Workspace.Music.MusicName.Value = "Alan Walker - Faded (Sep Remix)" Core.Change() script.Parent.Sound:Play() wait(119.98) script.Parent.Sound.SoundId = "rbxassetid://419901917" script.Parent.Sound:Play() end end
Module Script named Core:
local Core = {} function Change() game.Workspace.Music.MainText.Value = game.Workspace.Music.MusicName.Value end 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:
function Core.Change() -- ... 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:
local Core = { ["Change"] = function() -- ... end, -- Or, without square brackets: Change = function() -- ... end }
but it's not as easily readable.
You could also insert them afterwards:
local Core = {} local function Change() -- ... end Core["Change"] = Change -- Or, without square brackets: Core.Change = Change