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

How could I make a custom functioning leaderboard?

Asked by 9 years ago

Hi, I'm a beginner to Lua and was trying to make a custom leaderboard. It doesn't work too well.

Here's the leaderboard setup, the problem here is that it's only giving it to one player (the first one in the server).

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model", player)
    leaderstats.Name = "leaderstats"

    local stars = Instance.new("IntValue", leaderstats)
    stars.Name = "Stars"
    stars.Value = 0

    local points = Instance.new("IntValue", leaderstats)
    points.Name = "Points"
    points.Value = 0
end)

Another issue is with this script, where I'm trying to give players "Stars" every time they touch a block. It works, but again only with one person. I also need it so that when someone touches the block everybody gets teleported back to the spawn(s).

script.Parent.Touched:connect(function()
    for _,Player in pairs(game.Players:GetPlayers()) do
        if Player:FindFirstChild("leaderstats") then
            Player.leaderstats.Stars.Value = Player.leaderstats.Stars.Value + 1
        end
    end
    wait(10)
end)

My last question is how to make a script so that when someone kills someone they get a "Point".

If anybody could help me, it would be greatly appreciated.

1 answer

Log in to vote
2
Answered by
jakedies 315 Trusted Moderation Voter Administrator Community Moderator
9 years ago

Any weapon you may give players should create some indication of who hit the other player (most popular, the creator ObjectValue in the Humanoid referencing the player).

You can then attach the CharacterAdded and Died events and check if that tag exists in the humanoid, if so you can use the player it references and increase their points.

--At the end of your PlayerAdded event
player.CharacterAdded:connect(function(character)
    local humanoid = character.Humanoid; --reference the humanoid
    humanoid.Died:connect(function() --attach the Died event so we know when they died
        if humanoid:FindFirstChild("creator"); --if someone hit them with a tool that adds this
            local other = humanoid.creator.Value; --reference the killer
            other.leaderstats.Points.Value = other.leaderstats.Points.Value + 1; --add 1 point
        end
    end);
end);
0
Thanks I'll see if this works! FierceByte 25 — 9y
0
It works! Thank you so much. I wish I could vote up. :/ FierceByte 25 — 9y
1
No problem, and it's fine. The reason I'm here is to help people, not get some kind of reputation. jakedies 315 — 9y
Ad

Answer this question