-
What do you want to achieve?
I want to save a table of IntValues that are in ReplicatedStorage and their values are changed through a ServerScript in ServerScriptService. -
What is the issue?
The IntValues change, but it doesn’t seem to save the IntValues at all.
(These IntValues act as BoolValues, I want them to either be 1 or 0).
Output Before Player Buys Upgrade
Output After Player Buys Upgrade
-
What solutions have you tried so far?
I made a previous topic that was similar, but it was about the values not being changed and updated. Right now, it is changing and updating but it isn’t saving.
I also made a function to see if the values change, it is for sure 1.
ServerScript under two folders in ServerScriptService
(The Script is called ClassSaveScript)
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
game.Players.PlayerAdded:Connect(function()
print(Upgrade1.Value.." That was da value he he heh eh eh ehe")
end)
Upgrade1.Changed:Connect(function()
Upgrade1.Value = 1
print("Upgrade 1 Value is "..Upgrade1.Value)
end)
Upgrade2.Changed:Connect(function()
Upgrade2.Value = 1
end)
Upgrade3.Changed:Connect(function()
Upgrade3.Value = 1
end)
Upgrade4.Changed:Connect(function()
Upgrade4.Value = 1
end)
Upgrade5.Changed:Connect(function()
Upgrade5.Value = 1
end)
Upgrade6.Changed:Connect(function()
Upgrade6.Value = 1
end)
Upgrade7.Changed:Connect(function()
Upgrade7.Value = 1
end)
Upgrade8.Changed:Connect(function()
Upgrade8.Value = 1
end)
while task.wait(1) do
print("Upgrade 1 Value is probably being updated here ".. Upgrade1.Value)
local classTable = {Upgrade1.Value, Upgrade2.Value, Upgrade3.Value, Upgrade4.Value, Upgrade5.Value, Upgrade6.Value, Upgrade7.Value, Upgrade8.Value} -- This is the Table
end
--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)