I’m trying to pass some parameters through a script to a modulescript, although it’ll destroy the params value and replace the plr value with the original params value
Script:
game.ReplicatedStorage.Remotes.Admin.OnServerEvent:Connect(function(plr, command, params)
if table.find(UIds, plr.UserId) and commands[command] then
commands[command](plr, params)
end
end)
Module:
local datastore = require(game.ServerStorage.Modules.DataStore)
local command = {}
function command:gcash(plr, params)
local pastdata = datastore:GetPlayerData(plr)
local success, err = pcall(function()
datastore:UpdateAsync(plr.UserId, function(pastdata)
pastdata["Credits"] += params[1]
return pastdata
end)
end)
end
There’s a difference when defining functions within tables/modules.
If you define the function with a dot:
function module.foo(argument)
print(argument)
end
module.foo("Something") -- Prints "Something"
but when defining the function with a colon:
function module:foo(argument)
print(argument)
end
module.foo("Something") -- Prints "nil"
module:foo("Something") -- Prints "Something"
module["foo"]("Something") -- Prints "nil"
This is due to Lua’s syntax, when you define the function with a colon, the first passed variable is ‘self’ and depending on how you call the function defines which is the first passed variable. Calling a function with a colon makes the first passed variable itself which should be the table the function is defined in.