I have a simulator-type game using a linear layout that is made up of 5 zones. (like the pet sim x zones) I have a folder inside the player that is made up of 5 values indicating if the player owns the zone or not. I am trying to save those values into the roblox dataStores. The issue is that my data will not load properly.
local Players = game:GetService('Players')
local DSS = game:GetService("DataStoreService")
local zonesOwned = DSS:GetDataStore("zonesOwned")
-- Getting a data store
game.Players.PlayerAdded:Connect(function(plr)
local ZoneOwnershipValueFolder = plr:WaitForChild("ZoneOwnershipValueFolder")
local Zone2 = ZoneOwnershipValueFolder.Zone2Value
local Zone3 = ZoneOwnershipValueFolder.Zone3Value
local Zone4 = ZoneOwnershipValueFolder.Zone4Value
local Zone5 = ZoneOwnershipValueFolder.Zone5Value
local Zone6 = ZoneOwnershipValueFolder.Zone6Value
-- Getting the zones
local data
local success, errormessage = pcall(function()
data = zonesOwned:GetAsync(plr.UserId)-- getting a place to store the data
end)
if data ~= nil then
Zone2.Value = data[1]
Zone3.Value = data[2]
Zone4.Value = data[3]
Zone5.Value = data[4]
Zone6.Value = data[5]
print("Successfully gotten data")
-- tying the ZoneValues to data
else
print("unable of getting player data")
warn(errormessage)
end
end)
local function OnPlayerRemoving(plr)
local save = {}
table.insert(save,plr.ZoneOwnershipValueFolder.Zone2Value.Value)
table.insert(save,plr.ZoneOwnershipValueFolder.Zone3Value.Value)
table.insert(save,plr.ZoneOwnershipValueFolder.Zone4Value.Value)
table.insert(save,plr.ZoneOwnershipValueFolder.Zone5Value.Value)
table.insert(save,plr.ZoneOwnershipValueFolder.Zone6Value.Value)
-- The values again
print(save)
local success, errormessage = pcall(function()
zonesOwned:SetAsync(plr.UserId,save)-- Setting a place to store the data
end)
if success then
print("Data Has been Saved")
else
warn(errormessage)
end
end
Players.PlayerRemoving:Connect(OnPlayerRemoving)
game:BindToClose(function()
for i, player in pairs(Players:GetChildren()) do
OnPlayerRemoving(player)
-- checking when the plr left
end
end)
You can see the value changed but it did not save
Also tell me if you need the script that controls the GUI that says 'Would you like to buy zone3 for 50l"