95% of the time it works perfectly fine in game. Lets say you left "the game" with 101 Survivals. Then re-enter "the game" sometimes you get 0 for Survivals. But if you leave the game and re-enter "the game" again you get the 101 Survivals. Can someone please help me. Thank you so much!
local DataStoreService=game:GetService("DataStoreService")
local Players = game:GetService("Players")
local DataStore=DataStoreService:GetDataStore("Player_Data")
game.Players.PlayerAdded:connect(function(Player)
local Stats=Instance.new('IntValue')
Stats.Name="leaderstats"
local survivals=Instance.new('IntValue',Stats)
survivals.Name="Survivals"
survivals.Parent = Stats
Stats.Parent=Player
local CanSave=Instance.new('BoolValue',Player)
CanSave.Name="CanSaveData"
CanSave.Value=true
local Success,Message=pcall(function()
return DataStore:GetAsync(tostring(Player.UserId))
end)
if Success then
if DataStore~=nil then
Player.leaderstats.Survivals.Value=Message
else
Player.leaderstats.Survivals.Value=0
end
else
Player.CanSaveData.Value=false
Player:Kick("Your data failed to load! Please rejoin.")
end
end)

1 comment
Delete lines 24 and 25?