I'm making a round-type game, where players are getting points for a correct answer.
I'll like to give the player with most points (at the end of the round) a win, but I have no idea, how to do that. I have prepared both NumberValues in leaderstats. This is literally the last thing that separates me from finishing my game.
Can someone advise me? Thanks.
You could start by having a server script that waits for the game/round to finish that gathers all of the leaderstats NumberValues and compares them.
If you're stuck on how you could compare multiple players values, you could start by iterating through the players and storing any value that is higher than the previous one into a variable with the players name or ID. Personally I would use a For Loop to do this, after the loop is done I'd then check who won and give that player a win. Here is an example of how I would go about coding that:
local players = game:GetService("Players")
local function endRound()
-- Array that keeps track of winner for each round
local winner = {nil, 0}
-- Iterates through the players and compares points
for i, player in players:GetPlayers() do
if player.leaderstats.Points.Value > winner[2] then
winner = {player, player.leaderstats.Points.Value}
end
end
-- Adds 1 win to the wins of the Winner
winner[1].leaderstats.Wins.Value = winner[1].leaderstats.Wins.Value + 1
end
wait(60)
endRound()
I hope this helps, I did a few quick tests to make sure the code works as intended but it is probably far from perfect. I hope it gives you a rough idea of what to do if it doesn't answer the your question drop a comment and try to explain to me what you would like help with.
Something I realised while writing this is that if you did use that code you would need to make sure you had catches for when the highest points is shared by multiple players in a draw or when players all have 0 points to ensure the script does not break during gameplay.