Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Server script not letting me call a function in module script?

So basically im trying to make a user friendly settings module and make the function set a players cash to the starting cash amount inside of the function, startingcash in the module script. It should be a simple fix but im stupid so i need help!, Thanks

Module

local module = {}
function startingcash(player)
local startingcashamount = 10 -- Replace this number with starting cash amount!--
player.leaderstats.Cash.Value = startingcashamount
end

return module

ServerScript

game.Players.PlayerAdded:connect(function(plr)
	local leader = Instance.new("Folder",plr)
	leader.Name = "leaderstats"
	local cash = Instance.new("NumberValue",leader)
	cash.Name = "Cash"
	gamesettings.startingcash(plr)
end)

Error Inside of Serverscript: "00:30:33.496 - Workspace.Plieax's Tycoon Kit.Main Scripts.leaderboard:13: attempt to call field 'startingcash' (a nil value)"

2 comments

1

Show the script where you define gamesettings. Did you use "require"?

0

Part of the script*

2 answers

✓ Accepted answer

Line 1 of your server script. It’s :Connect, not :connect.

Line 2 of your module script should be:

function module.startingcash(player)
-- OR

function module:startingcash(player)

7 comments

0

sorry not the problem i just forgot to copy that

0

It is the problem. The deprecated code should be fixed, and adding the module. or module:

0

oh ok i didnt read the whole answer, thanks!

0

Deprecated code shouldn’t even be used anyways. I get an error for using connect it always says 'connect is not a valid member of RBXScriptSignal' so idk if it’s just me or it’s deprecated.

0

Wait im confused so what was the error.

1

^ I once used :connect to test it out and I got an error saying "connect is not a valid member of RBXScriptSignal”.

1

That's because you're trying to use connect on an event signal, not a listener. Event signals are short APIs for what connect returns, which is just a disconnector.

Put the module script data inside the curly bracket things whatever they're called again.

local module = {
function startingcash(player)
    local startingcashamount = 10 -- Replace this number with starting cash amount!--
    player.leaderstats.Cash.Value =  startingcashamount
end
}
return module

And your server script is even more messed up. Can you post more of it here please? Specifically up to line 13 where it errors. For one, you need to call modules with require()

gamesettings = require(PathToFindModuleScriptHere) -- should be self explanatory.
local leader = Instance.new("Folder",plr)
leader.Name = "leaderstats"
local cash = Instance.new("NumberValue",leader)
cash.Name = "Cash"
gamesettings.startingcash(plr)

7 comments

0

This is a better answer than mine. Upvote for you from me.

1

Although the function can just be inserted into the table with . or :

0

Nah his module script is fine. I have a feeling it's the defining of gamesettings where the error occurs.

1

True. Forgot the require maybe, or he didn’t know about it.

0

There are definitely more problems with the script than what I posted, I just tried to fix what I could.

1

Deprecated code being one, but I pointed it out.

0

The error is on line 13, but he never showed us what line 13 is.

This discussion is preserved as it was. New answers, comments, and votes are closed.