I have a folder that stores a couple of bool values, the folder is stored in ReplicatedStorage and I have a saving script that saves the values of the bool values, the problem is when I test the game and data works in studio btw, I have a shop and when I buy something the bool value of that specific item is set to true, then I leave the game, I rejoin and then find that all bool values are set to true and everything item is like "Equip" why is this happening when saving?
theres no error in the output, just prints that data got saved..
Serverscript: (saving script)
-- Services
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TagData = DataStoreService:GetDataStore("Test1")
-- Folders
local nametagPurchases = ReplicatedStorage:WaitForChild("NametagPurchases")
local firstPage = nametagPurchases.FirstPage
local function getTags() -- A function that gathers all the Bool Values and are store in a table.
local Tags = {} -- The table the boolvalues are stored in.
for _,tag in pairs(firstPage:GetChildren()) do
if tag:IsA("BoolValue") then
Tags[tag.Name] = tag.Value
end
end
return Tags
end
game.Players.PlayerAdded:Connect(function(player)
local TagValues = getTags() -- Variable that gets the table from the function
local data
local success, err = pcall(function()
data = TagData:GetAsync(player.UserId) -- get data
end)
if success then
for _,boolvalue in pairs(firstPage:GetChildren()) do -- Goes through all boolvalues in the folder and saves them one by one.
if boolvalue:IsA('BoolValue') then
boolvalue.Value = data
end
end
else
print("There was an error getting the tag values when player was added")
warn(err)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local TagValues2 = getTags() -- gets table
local success,err = pcall(function()
TagData:SetAsync(player.UserId, TagValues2) -- saves the data
end)
if success then
print("All tag values are saved!")
else
print("There was an error saving the tag values when player left.")
warn(err)
end
end)
pls help pls pls
