Hey guys today i was scripting and i saw a problem with my leaderstats i cant find out the problem why my points and wins not showing up? can you guys help me and this is my script: local ds = game:Getservice(“DataStoreService”)
local stats = ds:GetDataStore(“playerStats_00”)
function getplayerData(player)
local success, data = false, nil
repeat
success = pcall(function()
data = stats:GetAsync(player.UserId)
end)
until success
player.DataLoaded.Value = true
return data
end
function savePlayerData(player)
if player.DataLoaded.Value then
local data = {}
for i,v in pairs(player.leaderstats:GetChildren()) do
table.insert(data, v.Value)
end
pcall(function()
stats:SetAsync(player.UserId, data)
end)
end
end
function giveStats(player)
local leaderstats = Instance.new(“Folder”, player)
leaderstats.Name = “leaderstats”
local Points = Instance.new("IntValue", leaderstats)
Points.Name = "Points"
local Wins = Instance.new("IntValue", leaderstats)
Wins.Name = "Wins"
local loaded = Instance.new("BoolValue", player)
loaded.Name = "DataLoaded"
local data = getplayerData(player)
if data then
Points.Value = 0
Wins.Value = 0
end
local DataStoreService = game:GetService("DataStoreService")
local stats = DataStoreService:GetDataStore("playerStats_00")
function getplayerData(player)
local success, data = false, nil
local tries = 3
repeat
success = pcall(function()
data = stats:GetAsync(player.UserId)
end)
if not success then
wait(1)
end
tries -= 1
until tries == 0 or success
player.DataLoaded.Value = true
if success then
if data then
-- Data exists for this player
return data
else
-- Data store is working, but no current data for this player
return
end
else
warn("Cannot access data store for player!")
end
end
function savePlayerData(player)
if player.DataLoaded.Value then
local data = {}
for _, v in pairs(player.leaderstats:GetChildren()) do
table.insert(data, v.Value)
end
local tries = 3
local success
repeat
success = pcall(function()
stats:SetAsync(player.UserId, data)
end)
if not success then
wait(1)
end
tries -= 1
until tries == 0 or success
if not success then
warn("Cannot save data for player!")
end
end
end
function giveStats(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Points = Instance.new("IntValue")
Points.Name = "Points"
Points.Parent = leaderstats
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Parent = leaderstats
local loaded = Instance.new("BoolValue")
loaded.Name = "DataLoaded"
loaded.Parent = player
local data = getplayerData(player)
if data then
Points.Value = 0
Wins.Value = 0
end
end
game:GetService("Players").PlayerAdded:Connect(giveStats)
game:GetService("Players").PlayerRemoving:Connect(savePlayerData)
while true do
wait(30)
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
savePlayerData(player)
end
end
This basically only had two syntax errors, but I changed other parts following good practices.