I want to call a module script to first check if the player has enough money and then remove a specific amount of money, I want to do this efficiently so I use a module script
game.ReplicatedStorage.Events.Placement.OnServerEvent:Connect(function(plr,place,tower)
if place and tower then
local unit = script.Units.Starting:FindFirstChild(tower)
local slot = workspace.Placement:FindFirstChild(place)
if unit and slot then
if currency:checkMoney(plr) >= unit.Cost.Value then
currency:removeMoney(plr,unit.Cost.Value)
loadUnit(unit,slot,plr)
end
end
end
end)
This is the portion of the code that matters
I get this error when trying.

and this is the module script portion that matters.
I hope you can help me, thanks in advance.
The problem here is how you’re calling your module member functions.
Since your member functions are defined with the dot operator, that is also how they should be called so that the parameters pass correctly.
In this example since you call your member functions with a colon, in simplest terms what’s happening is that the module
table object itself is implicitly getting passed as the first parameter.
So for example, plr
is actually a reference to the module
table object, not the actual parameter that’s being sent through the function call.
Again, this is a result of the following:
local myThing = {}
function myThing.test(someParameter)
print(someParameter) --> will print the myThing table, not 45.
end
myThing:test(45) --//For the actual parameter value to be preserved, this function should also be called with the dot operator.
4 Likes