Please Help with Data Saver.rbxl (73.3 KB)
I need help saving the date of what cards have been equiped to load when the game starts, so far the bugs i found is that when i reset the card i equip dissapear and when i rejoin the cards that were equiped dissapear too, i need help saving the these datas of wish i tried inside the game file but clearly seems impossible
to save and load the cards that players have equipped you can use datastore to store the data and retrieve it when the player joins or resets here is an example of how you can implement it
- saving the card data when a player equips a card
local datastoreService = game:GetService("DataStoreService")
local cardDataStore = datastoreService:GetDataStore("CardDataStore")
local function saveEquippedCards(player, equippedCards)
local success, errorMessage = pcall(function()
cardDataStore:SetAsync(player.UserId, equippedCards)
end)
if not success then
warn("failed to save card data: " .. errorMessage)
end
end
-- example of saving data when a player equips a card
local function equipCard(player, cardId)
local equippedCards = {} -- get the current equipped cards (this could be a table of card ids)
table.insert(equippedCards, cardId)
saveEquippedCards(player, equippedCards)
end
2. loading the card data when the game starts
local function loadEquippedCards(player)
local success, equippedCards = pcall(function()
return cardDataStore:GetAsync(player.UserId)
end)
if success and equippedCards then
-- equip the cards stored in the data
for _, cardId in pairs(equippedCards) do
-- code to equip the card based on cardId
print("equipping card: " .. cardId)
end
else
-- if there is no saved data equip default cards or handle the situation
print("no saved card data for player")
end
end
game.Players.PlayerAdded:Connect(function(player)
loadEquippedCards(player)
end)
- datastoreService is used to save and load player specific data
- setasync saves the equipped cards data while getasync retrieves it
- playeradded is triggered when a player joins which is where you load their equipped cards
this should help save and load the equipped cards even when a player resets or rejoins. let me know if it works
if you want to use your own code and want to make a costum one follow the explanation at the end to make it mine is rushed just so you know
thank you so much im going to give it a try
no problem tell me if it dosent work becouse i can give it to my friend that has one decade of experence and can do this no problem
that would be very appreciated , thank you again
i will tell him i dont have very experience with scripting becouse i specialize in building
understood but your effort was very kind