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

How do I work with module script for data savings?

Asked by
Yuuwa0519 197
4 years ago

I have recently been working on data storing system via module script, which can be required from any server script. However, I came across with this problem which I can't solve it because I have little knowledge about modules. If you see any problems with my script or have any suggestion, I am always open for it. Thank you for any helps

--module script
local playerData = {}
return playerData

--serverscript
local MPS = game:GetService("MarketPlaceService")
local plrData = require(script.Parent.ModuleScript)
local shopData =  require(script.Parent.ModuleScript2)
local remote = game.ReplicatedStorage.buyRemote


function completePurchase(plr,id)
    local item = --iterate shopData to find the item 
    if plr and item then
        local customerData - plrData[plr.UserId]
        customerData["cash"] = customerData["cash"] + item["GivingValue"]
    end
end
function purchaseRequest(plr,item)
    if plr then
        local item = shopData[item]
        if item then
            MPS:PromptProductPurchase(plr,item["ProductId"])
        end
    end
end

function proccessRecipit(plr,id)
    local player = game.Players:GetPlayerByUserId(plr)
    if not player then  
        return Enum.ProductPurchaseDecision.NotProccessedYet
    end
    completePurchase(player,id)
    return Enum.ProductPurchaseDecision.PurchaseGranted
end

MPS.ProccessRecipit = proccessRecipit   
remote.OnServerInvoke = purchaseRequest

Answer this question