so i checked the player, there IS a leaderstats folder.
but no “Wins” IntValue inside the folder?
local DSS = game:GetService("DataStoreService")
local WinsDataStore = DSS:GetDataStore("Wins")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = plr
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Value = WinsDataStore:GetAsync(plr.UserId) or 0
Wins.Parent = ls
end)
Players.PlayerRemoving:Connect(function(plr)
WinsDataStore:SetAsync(plr.UserId, plr.leaderstats.Wins.Value)
end)
game:BindToClose(function()
for i, plr in pairs(Players:GetPlayers()) do
WinsDataStore:SetAsync(plr.UserId, plr.leaderstats.Wins.Value)
end
end)
so the problem is NOT about the datastore, the problem is about the intvalue itself, it is not even appearing on the leaderstats.
local Players = game:GetService("Players")
local TestService = game:GetService("TestService")
local RunService = game:GetService("RunService")
local DSS = game:GetService("DataStoreService")
local WinsDataStore = DataStoreService:GetDataStore("Wins") --Name the DataStore whatever you want
Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Parent = leaderstats
Wins.Value = 0
local value1Data = Wins
local s, e = pcall(function()
value1Data = WinsDataStore:GetAsync(plr.UserId..'-Value1') or 0 --check if they have data, if not it'll be "0"
end)
if s then
Wins.Value = value1Data --setting data if its success
else
TestService:Error(e) --if not success then we error it to the console
end
end)
Players.PlayerRemoving:Connect(function(plr)
local s, e = pcall(function()
WinsDataStore:SetAsync(plr.UserId..'-Value1', plr.leaderstats.Wins.Value) --setting data
end)
if not s then TestService:Error(e)
end
end)
game:BindToClose(function(plr)
if not RunService:IsStudio() then
local s, e = pcall(function()
WinsDataStore:SetAsync(plr.UserId..'-Value1', plr.leaderstats.Wins.Value) --setting data
end)
if not s then TestService:Error(e)
end
end)
end)