Hey guys, it is my first time attempting to use DataStore2 in a game of mine. Right now, I am working on a skin system, and each skin has its own value, meaning when a skin is purchased, the value of the skin is set to true. Looking for an efficient way to have a bunch of values under one section in DataStore2, I decided to create a table and put all of these values under one variable. Please bear with me as I may be doing things completely wrong, and this is my first time using this!
Basically, I want to know how to find specific values from a table I created, and change it. When a textbutton is clicked, it fires a message to the server telling it the information of the skin (The price and name of the skin) On this server event, I have it so it checks if the player can afford to go through with this event, and I have it so it removes the currency, but I don’t know how to make it so it sets the skin value to true. Could someone possibly assist me with this? The script is attached below
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local DataStore2 = require(1936396537)
local defaultcurrencyamount = 2500
local DefaultSkinEquipped = "DefaultSkin"
local DefaultItemsOwned =
{["Samurai"] = false,
["DarkBomber"] = false,
["Ninja'] = false
}
players.PlayerAdded:Connect(function(plr)
local CashStore = DataStore2("Cash", plr)
local SkinEquipped = DataStore2("SkinEquipped", plr)
local ItemsOwnedTable = DataStore2("ItemsOwned", plr)
local function updateClientCurrency(amount)
replicatedStorage.UpdateClientCurrency:FireClient(plr, amount)
end
local function SkinsOwnedUpdate(skintable)
replicatedStorage.SendBackToClientShop:FireClient(plr, skintable)
end
local function SkinsOwnedUpdate(ItemsOwned)
replicatedStorage.SendBackToClientShop:FireClient(plr, ItemsOwned)
end
updateClientCurrency(CashStore:Get(defaultcurrencyamount))
SkinsOwnedUpdate()
CashStore:OnUpdate(updateClientCurrency)
end)
game.ReplicatedStorage.Purchase.OnServerEvent:Connect(function(plr, TypeOfPurchase, Price, Name)
if TypeOfPurchase == "Shop" then
local CashStore = DataStore2("Cash", plr)
local ItemsOwnedTable = DataStore2("ItemsOwned", plr)
if CashStore:Get(defaultcurrencyamount) >= Price then
CashStore:Increment(-Price)
print("This would be where I would want the line that changes the value in the table")
end
end
end)