Problem
I can’t save a table of intvalues, or my logic to fire remote events is wrong.
What I’ve Tried
Using DataStore to keep the intvalue table saved. I reused code to save a single intvalue.
(I think my remote events aren’t firing but I’ll make another topic for that)
Code
local Upgrade1 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave1
local Upgrade2 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave2
local Upgrade3 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave3
local Upgrade4 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave4
local Upgrade5 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave5
local Upgrade6 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave6
local Upgrade7 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave7
local Upgrade8 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave8
local classTable = {Upgrade1.Value, Upgrade2.Value, Upgrade3.Value, Upgrade4.Value, Upgrade5.Value, Upgrade6.Value, Upgrade7.Value, Upgrade8.Value}
--Data Store
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
local classStore = DataStoreService:GetDataStore("JuggernautStore")
local players = game:GetService("Players")
local function onShutDown()
task.wait(3)
end
local function setUp(player)
local userID = player.UserId
local key = "Player_"..userID
local data = classStore:GetAsync(key)
local success, ret = pcall(classStore.GetAsync, classStore, key)
if success then
classTable = ret or 0
else
print("Uh oh there's an error man "..ret)
end
repeat
local success, ret = pcall(classStore.GetAsync, classStore, key)
until success or not players:FindFirstChild(players.Name)
classTable = data or 0
end
local function save(player)
local userID = player.UserId
local key = "Player_"..userID
wait(6)
classStore:SetAsync(key, classTable)
local success, ret = pcall(classStore.SetAsync, classStore, key)
if success then
print("Yippee! The Upgrade have been SAVED")
else
print("Uh oh there's an error man "..ret)
end
repeat
local success, ret = pcall(classStore.SetAsync, classStore, key)
until success or not players:FindFirstChild(players.Name)
end
while wait(60) do
players.PlayerRemoving:Connect(save)
end
game:BindToClose(onShutDown)
players.PlayerAdded:Connect(setUp)
players.PlayerRemoving:Connect(save)