Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Two Leaderboards not working?

Asked by 4 years ago
Edited 4 years ago

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. :)

0
See my edited script it will start deaths at 0 Shounak123 461 — 4y
0
And it will not show the error Shounak123 461 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
Thank you very much, but it doesn't work 100%. Every player starts with 1 death, and the time is stuck at 0. There also is an error: "ServerScriptService.Script:18: attempt to index nil with 'Value'". But the death counter works :) Macperolek 7 — 4y
0
I have improved it please try to replace it again Shounak123 461 — 4y
Ad

Answer this question