Im making a trading system and I’m using a module script to get the players data to ofcourse show it and allow it to be traded and stuff. However, the players data is only on the server and can only be accessed from that one script, how can I send that data to the module script when I have to?
Heres what the module script looks like, it currently uses tools but I wanna change that to the players data:
local config = {}
-------Settings you can change-------
config.MaxSlots = 9
config.TimeBeforeTradeConfirmed = 10
-------------------------------------
--Funcion for getting all the tools a player has
function config.GetTools(plr)
local plrTools = plr.Backpack:GetChildren()
local toolEquipped = plr.Character:FindFirstChildOfClass("Tool")
if toolEquipped then
table.insert(plrTools, toolEquipped)
end
return plrTools
end
return config
For reference, the data on the server script looks like this:
local data = {}
local function loadData(player)
local success = nil
local playerData = nil
local attempt = 1
repeat
success, playerData = pcall(function()
return dataBase:GetAsync(player.UserId)
end)
attempt += 1
if not success then
warn(playerData)
task.wait()
end
until success or attempt == 3
if success then
if not playerData then--give default data if they're new
playerData = {
["Gems"] = 0,
["SelectedTowers"] = {"Cameraguy"},
["OwnedTowers"] = {"Cameraguy"},
["MaxTowers"] = 5,
["RedeemedCodes"] = {}
}
beamEvent:FireClient(player)
end
data[player.UserId] = playerData
If you could help asap that would be appreciated because i gtg soon and i wanna get this done quickly lol, have a great day!