hey there, I have a script for saving a number value and it’s not saving help would be appreciated.
local DataStoreService = game:GetService("DataStoreService")
local SettingTest = DataStoreService:GetDataStore("SettingTest")
function OnPlayerAdded(player)
local folder = Instance.new("Folder")
folder.Name = "Settings"
folder.Parent = player
local Setting1 = Instance.new("NumberValue")
Setting1.Name = "Test"
Setting1.Parent = player.Settings
Setting1.Value = 0
local SettingDataLoaded = Instance.new("BoolValue", player)
SettingDataLoaded.Name = "SettingDataLoaded"
SettingDataLoaded.Value = false
local data
local attempts = 10
repeat
local success, err = pcall(function()
data = SettingTest:GetAsync(player.UserId)
end)
if success then
print("success")
SettingDataLoaded.Value = true
break
else
warn("Was problem with datastore! (Attempts left ", attempts, ")")
end
task.wait(1)
attempts = attempts - 1
until attempts <= 0
if not SettingDataLoaded.Value then
warn("Player " .. player.Name .. "'s data has not been loaded!")
player:Kick("Couldn't load your data, try to rejoin later")
return
end
end
function OnPlayerRemoving(player)
if player:FindFirstChild("SettingDataLoaded") and player.SettingDataLoaded.Value == true then
local attempts = 10
repeat
local success, err = pcall(function()
SettingTest:SetAsync(player.UserId, player.Settings:FindFirstChild("Test").Value)
end)
if success then
print("Success!")
else
warn("Was problem with datastore! (Attempts left ", attempts, ")")
end
task.wait(1)
attempts = attempts - 1
until attempts <= 0
if attempts <= 0 then
warn("Player " .. player.Name .. "'s cash data has not been saved!")
end
end
end
game.Players.PlayerAdded:Connect(OnPlayerAdded)
game.Players.PlayerRemoving:Connect(OnPlayerRemoving)