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

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

Asked by
Plieax 66
6 years ago
Edited 6 years ago

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)"

1
Show the script where you define gamesettings. Did you use "require"? TiredMelon 405 — 6y
0
Part of the script* TiredMelon 405 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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)
0
sorry not the problem i just forgot to copy that Plieax 66 — 6y
0
It is the problem. The deprecated code should be fixed, and adding the module. or module: User#19524 175 — 6y
0
oh ok i didnt read the whole answer, thanks! Plieax 66 — 6y
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. User#19524 175 — 6y
View all comments (3 more)
0
Wait im confused so what was the error. TiredMelon 405 — 6y
1
^ I once used :connect to test it out and I got an error saying "connect is not a valid member of RBXScriptSignal”. User#19524 175 — 6y
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. ScriptGuider 5640 — 6y
Ad
Log in to vote
1
Answered by 6 years ago

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)
0
This is a better answer than mine. Upvote for you from me. User#19524 175 — 6y
1
Although the function can just be inserted into the table with . or : User#19524 175 — 6y
0
Nah his module script is fine. I have a feeling it's the defining of gamesettings where the error occurs. TiredMelon 405 — 6y
1
True. Forgot the require maybe, or he didn’t know about it. User#19524 175 — 6y
View all comments (3 more)
0
There are definitely more problems with the script than what I posted, I just tried to fix what I could. protectiveebob 221 — 6y
1
Deprecated code being one, but I pointed it out. User#19524 175 — 6y
0
The error is on line 13, but he never showed us what line 13 is. protectiveebob 221 — 6y

Answer this question