Hi, I'm using a Module Script to store and send data to other parts of my game, so to make sure the system would work I set up a small test, which is proving to be more difficult than I thought. The below code is from the ModuleScript, which has a folder inside of it. Inside the folder are different types of values.
TL;DR read output
local library = {} function loadpokemon(PokeID) local pokefile = game.Workspace.Library:FindFirstChild(PokeID) local pokename = pokefile.PokemonName.Value local pokehealth = pokefile.Health.Value local stats = {pokename, pokehealth} print("Pokemon name: "..stats[1]) print("Pokemon health: "..stats[2]) end return library
Now I have a normal Script that is attempting to use the function above. It sends the value 25, which is the ID I use to identify Pikachu.
local library = require(game.Workspace.Library) library.loadpokemon(25)
The error I receive is:
Workspace.Script:5: attempt to call field 'loadpokemon' (a nil value)
Thanks for any help.
You'll have to index the function into the library table.
local library = {} library.loadpokemon = function(PokeID) local pokefile = game.Workspace.Library:FindFirstChild(PokeID) local pokename = pokefile.PokemonName.Value local pokehealth = pokefile.Health.Value local stats = {pokename, pokehealth} print("Pokemon name: "..stats[1]) print("Pokemon health: "..stats[2]) end return library
Just in case: