I've literally been looking for hours for a fix for this and it's a real headache. If someone could help me, that'd be greatly appreciated.
code:
_G.infinite=game.ReplicatedStorage.infinite.Value
local DataStoreService=game:GetService("DataStoreService")
local ds=DataStoreService:GetDataStore("Player_Data")
game.Players.PlayerAdded:connect(function(plr)
local leaderstats=Instance.new("IntValue",plr);leaderstats.Name="leaderstats"
local clout=Instance.new("IntValue",leaderstats);clout.Name="Clout"
local coins=Instance.new("IntValue",plr);coins.Name="Coins"
local storage=Instance.new("NumberValue",plr);storage.Name="Storage"
local equipped=Instance.new("ObjectValue",plr);equipped.Name="equipped";equipped.Value=game.ReplicatedStorage.FlexTools:FindFirstChild("1¢")
storage.Value=5
local clout_multiplier=Instance.new("NumberValue",plr);clout_multiplier.Name="clout_multiplier";clout_multiplier.Value=1
local coin_multiplier=Instance.new("NumberValue",plr);coin_multiplier.Name="coin_multiplier";coin_multiplier.Value=1
local dela=Instance.new("BoolValue",plr);dela.Name="DelayActive";dela.Value=false
local rank=Instance.new("StringValue",plr.leaderstats);rank.Name="Rank";rank.Value="Noob"
local dsLoaded=Instance.new("BoolValue",plr);dsLoaded.Name="dsLoaded"
--Datastore Part--
local PlayerData;
local CanSave=Instance.new('BoolValue',plr)
CanSave.Name="CanSaveData"
CanSave.Value=true
local DataFetchSuccess,ErrorMessage=pcall(function()
PlayerData=ds:GetAsync(tostring(plr.UserId))
end)
if DataFetchSuccess then --Data successfully loaded.
dsLoaded.Value=true
print("player data loaded,")
if PlayerData~=nil then
--[[
local t=PlayerData
plr.leaderstats.Clout.Value=t.clout
plr.leaderstats.Rank.Value=t.rank
plr.Storage.Value=t.storage
plr.Coins.Value=t.coins
plr.equipped.Value=t.equipped
plr.coin_multiplier.Value=t.multiplier
plr.clout_multiplier.Value=t.cMultiplier
--]]
else
local first=Instance.new("Model",plr);first.Name="FirstTime"
end
else
plr.CanSaveData.Value=false
plr:Kick("Your data failed to load, please try again in a few minutes.")
end
end)
game.Players.PlayerRemoving:connect(function(plr)
if plr.CanSaveData.Value==false then return end
print("player leaving and can save data.")
local PlayerData={
clout=plr.leaderstats.Clout.Value,
rank=plr.leaderstats.Rank.Value,
storage=plr.Storage.Value,
coins=plr.Coins.Value,
equipped=plr.equipped.Value,
multiplier=plr.coin_multiplier.Value,
cMultiplier=plr.clout_multiplier.Value
}
local DataWriteSuccess,ErrorMessage=pcall(function()
ds:SetAsync(tostring(plr.UserId),{PlayerData})
print(PlayerData)
end)
if not DataWriteSuccess then --Well ship, this might go bad for the player. Sorry player :/
print("poop")
local Retry_Count=0
while Retry_Count<6 do
wait(60)
local Succeded,Error=pcall(function()
ds:SetAsync(tostring(plr.UserId),PlayerData)
end)
if Succeded then break end
Retry_Count=Retry_Count+1
end
end
end)

3 comments
Were is the error? Since I can't find it I would say use different datastores to save each data of the player. Like saving coins would be 1 datastore and the 2nd would be PlayerWeapons (to save a person's weapons, just create codes for each weapon the player has.)
where*
It just fails to save (line 64)