So I have three different leader stats folders in the player service: one for counting a players deaths, time spent in-game and their stage in the lobby but when I run my game it says that all three leader stats folders are not a member of the player. When I look at my player service in my character while in-game, there are three leader stats folders.
Deaths script:
local plrs = game.Players
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Deaths") -- Change this with a different name.
print ("Deaths leaderstats working")
plrs.PlayerAdded:Connect(function(plr)
local jats = Instance.new("Folder")
jats.Name = "leaderstats"
jats.Parent = plr
local wipeouts = Instance.new("IntValue")
wipeouts.Name = "Deaths"
wipeouts.Value = 0
wipeouts.Parent = jats
local Data = DataStore:GetAsync(plr.UserId)
if Data then
wipeouts.Value = Data
end
game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId, Player.leaderstats.Death.Value) -- Change "Money" with your currency.
end)
plr.CharacterAdded:Connect(function(char)
local humanoid = char:FindFirstChild("Humanoid")
humanoid.Died:Connect(function()
wipeouts.Value = wipeouts.Value + 1
end)
end)
end)
Time spent script =
local plrs = game.Players
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Seconds") -- Change this with a different name.
print ("Time leaderstats working")
plrs.PlayerAdded:Connect(function(plr)
local jats =Instance.new("Folder")
jats.Name = "leaderstats"
jats.Parent = plr
local wipeouts = Instance.new("IntValue")
wipeouts.Name = "Seconds"
wipeouts.Value = 0
wipeouts.Parent = jats
local Data = DataStore:GetAsync(plr.UserId)
if Data then
wipeouts.Value = Data
end
game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId, Player.leaderstats.Seconds.Value) -- Change "Money" with your currency.
end)
plr.CharacterAdded:Connect(function(char)
while true do
wait(2)
wipeouts.Value = wipeouts.Value + 1
end
end)
end)
Stage script:
local dss = game:GetService("DataStoreService")
local obbyDS = dss:GetDataStore("ObbyData")
local checkpoints = workspace.Checkpoints
print("Checkpoint leaderstats working")
game.Players.PlayerAdded:Connect(function(plr)
local obbyData = obbyDS:GetAsync(plr.UserId .. "-obbyStageProgress")
local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = plr
local stage = Instance.new("StringValue")
stage.Name = "Stage"
stage.Value = obbyData or 1
stage.Parent = ls
local char = plr.Character or plr.CharacterAdded:Wait()
char:WaitForChild("HumanoidRootPart").CFrame = checkpoints[stage.Value].CFrame
char.Humanoid.Touched:Connect(function(touch)
if touch.Parent == checkpoints then
if (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(stage.Value)) or touch.Name == "End" then
stage.Value = touch.Name
pcall(function()
obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress", plr.leaderstats.Stage.Value)
end)
end
end
end)
plr.CharacterAdded:Connect(function(char)
local hrp = char:WaitForChild("HumanoidRootPart")
local humanoid = char:WaitForChild("Humanoid")
hrp:GetPropertyChangedSignal("CFrame"):Wait()
hrp.CFrame = checkpoints[stage.Value].CFrame
humanoid.Touched:Connect(function(touch)
if touch.Parent == checkpoints then
if (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(stage.Value)) or touch.Name == "End" then
stage.Value = touch.Name
pcall(function()
end)
game.Players.PlayerRemoving:Connect(function(player)
obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress", plr.leaderstats.Stage.Value)
end)
end
end
end)
end)
end)
This only started happening after I implemented a leaderboard for whoever has played the longest:
local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("WinsLeaderBoard")
local function updateLeaderboard()
local success, errorMessage = pcall (function()
local Data =WinsLeaderboard:GetSortedAsync(false, 5)
local WinsPage = Data:GetCurrentPage()
for Rank, data in ipairs(WinsPage) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local Seconds = data.value
local isOnLeaderboard = false
for i, v in pairs(game.Workspace.Leaderboardarea.Leaderboard.LeaderboardGUI.Holder:GetChildren()) do
if v.Name2.Text == Name then
isOnLeaderboard = true
break
end
end
if Seconds and isOnLeaderboard == false then
local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
newLbFrame.Name2.Text = Name
newLbFrame.TimeSpent.Text = Seconds
newLbFrame.Rank.Text = "#"..Rank
newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 * #game.Workspace.Leaderboardarea.Leaderboard.LeaderboardGUI.Holder:GetChildren()), 0)
newLbFrame.Parent = game.Workspace.Leaderboardarea.Leaderboard.LeaderboardGUI.Holder
end
end
end)
if not success then
print(errorMessage)
end
end
local g =0
wait(30)
while true do
for _, player in pairs(game.Players:GetPlayers()) do
WinsLeaderboard:SetAsync(player.UserId, player.leaderstats.Seconds.Value)
end
for _, frame in pairs (game.Workspace.Leaderboardarea.Leaderboard.LeaderboardGUI.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
g = g+1
print("Updated!",g)
wait(60)
end

1 comment
thanks for the answer