I want to have 2 leaderboards in my Roblox game. One which shows In-Game time (in seconds) and the second one which shows the number of deaths after clicking the join button.
I found 2 tutorials on youtube. Both of them work but when I enable the Number of deaths script, the In-Game Time script doesn't work.
This is the In-Game Time script I use:
function onPlayerEntered(newPlayer) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local secs = Instance.new("IntValue") secs.Name = "Time" secs.Value = 0 secs.Parent = stats stats.Parent = newPlayer while true do wait(1) secs.Value = secs.Value + 1 end end game.Players.ChildAdded:connect(onPlayerEntered)
And this is the Number of deaths script I use:
game:GetService('Players').PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() print(player.Name .. " has died!") player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value + 1 end) end) end) game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model", player) leaderstats.Name = "leaderstats" end) game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model", player) leaderstats.Name = "leaderstats" local score = Instance.new("IntValue", leaderstats) score.Name = "Deaths" score.Value = 0 end)
Of course, I don't need to use any of these scripts, they can be changed.
I'm not a good scripter and I need help. Thank you in advance. :)
I think I know what is causing the problem. You have inserted the leaderstats too many times in a single player, using too many scripts. Delete all scripts, then insert a script in the ServerScriptService and write the following:
game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" local Deaths = Instance.new("IntValue", leaderstats) Deaths.Name = "Deaths" Deaths.Value = 0 local Secs = Instance.new("IntValue", leaderstats) Secs.Name = "Time" leaderstats.Parent = player player.CharacterAdded:Connect(function() Deaths.Value = Deaths.Value + 1 end) while true do Secs.Value = Secs.Value + 1 wait(1) end end)
Remember to delete all other leaderstats scripts you have mentioned up in your question. If you do all the things I said correctly, you will get a 100% successful leaderstats which are counting Time and Deaths of player.