Hi
I have made a datastore script, which holds multiple IntValues. It has been working for a while, but suddenly all the values have been resetting to 0.
Script:
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents")
local LoadData = RS:FindFirstChild("LoadData")
local playerData = DataStoreService:GetDataStore("PFStores")
local function onPlayerJoin(player)
local Folder = Instance.new("Folder" , player)
Folder.Name = "Settings"
local FOV = Instance.new("IntValue" , Folder)
FOV.Name = "FOV"
local Time = Instance.new("IntValue" , Folder)
Time.Name = "Time"
local Brightness = Instance.new("IntValue" , Folder)
Brightness.Name = "Brightness"
local Cooldown = Instance.new("IntValue" , Folder)
Cooldown.Name = "Cooldown"
local Seconds = Instance.new("IntValue" , Folder)
Seconds.Name = "Seconds"
local playerUserId = "Player_" .. player.UserId
local data = playerData:GetAsync(playerUserId)
if data then
FOV.Value = data[1]
Time.Value = data[2]
Brightness.Value = data[3]
Cooldown.Value = data[4]
Seconds.Value = data[5]
LoadData:FireClient(player)
else
FOV.Value = 70
Time.Value = 12
Brightness.Value = 1
Cooldown.Value = 0.075
Seconds.Value = 0
LoadData:FireClient(player)
end
end
local function create_table(player)
local player_stats = {}
for _, stat in pairs(player.Settings:GetChildren()) do
player_stats[stat.Name] = stat.Value
end
return player_stats
end
local function onPlayerExit(player)
local player_stats = create_table(player)
local success, err = pcall(function()
local playerUserId = "Player_" .. player.UserId
playerData:SetAsync(playerUserId, player_stats)
end)
if not success then
warn('There was a DataStore error: ' .. err)
end
end
Players.PlayerAdded:Connect(onPlayerJoin)
Players.PlayerRemoving:Connect(onPlayerExit)
Any help would be appriciated, thanks!