So I'm working on a game with my friend and we have these game upgrades that unlock new stuff, but I'm wondering how I could save them?
My purchase module is set up like this:
local module = {}
local Upgrades = {
{ id = "idForThing", cash = 20, callback = function(player)
-- hi!
end, unlimitedPurchases = true, purchased = false }
}
module.getUpgrade = function(upgradeID)
for i, upg in pairs(Upgrades) do
if upg.id == upgradeID then
return upg
else
continue
end
end
return nil
end
module.getUpgrades = function()
return Upgrades
end
module.purchaseUpgrade = function(player, upgradeID)
for i, upg in pairs(Upgrades) do
if upg.id == upgradeID then
if upg.purchased then
SFX.Error:Play()
break
end
if game:GetService("ServerStorage").Cash.Value >= upg.cash then
game:GetService("ServerStorage").Cash.Value -= upg.cash
upg.purchased = not upg.unlimitedPurchases
upg.callback(player)
SFX.Purchased:Play()
else
SFX.Error:Play()
end
break
else
continue
end
end
end
return module
So, basically in the Upgrades table it has items that contain 5 values.
- id
The item ID
- cash
The amount it costs
- callback
Code that runs when purchased
- unlimitedPurchases
If it's true, you can purchase said item more than once
- purchased
Changes to true when the player purchases the item.
I made module.getUpgrades in hopes that I could just copy the Upgrades table to the DataStore but then it'd also copy the cash which I don't want. I just want it to copy the id and purchased value. So how would I copy just the id and purchased value?