Hello!
I’m making my data stores and when I getting values it works
but when I saving datas it probably do not handle it bc still it saying new player unless I have been joined
My script:
local ServerData = game:GetService("DataStoreService"):GetDataStore("Global_Leaderstats")
game.Players.PlayerAdded:Connect(function(plr)
print("Player joined")
local CoinsClientData = ServerData:GetAsync(plr.UserId.."-Coins")
local PetsClientData = ServerData:GetAsync(plr.UserId.."-Pets")
local EffectsClientData = ServerData:GetAsync(plr.UserId.."-Effects")
local Leaderstats = Instance.new("Folder",plr)
Leaderstats.Name = "leaderstats"
local Coins = Instance.new("IntValue",Leaderstats)
Coins.Name = "Coins"
plr2 = plr
if PetsClientData ~= nil and CoinsClientData ~= nil and EffectsClientData ~= nil then
Coins.Value = CoinsClientData
PetsClientData.Parent = plr
EffectsClientData.Parent = plr
print("Pets and Coins laoded in")
else
Coins.Value = 0
local PetsFolder = Instance.new("Folder",plr)
PetsFolder.Name = "Pets"
local EffectFolder = Instance.new("Folder",plr)
EffectFolder.Name = "Effects"
print("No data to load! Loading into game a new player!")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
ServerData:SetAsync(plr.UserId.."-Coins",plr.leaderstats.Coins.Value)
ServerData:SetAsync(plr.UserId.."-Pets",plr.Pets)
ServerData:SetAsync(plr.UserId.."-Effects",plr.Effects)
end)
game:BindToClose(function()
ServerData:SetAsync(plr2.UserId.."-Coins",plr2.leaderstats.Coins.Value)
ServerData:SetAsync(plr2.UserId.."-Pets",plr2.Pets)
ServerData:SetAsync(plr2.UserId.."-Effects",plr2.Effects)
end)
Thank for any help!