Winner Leaderboard

Hey!
So recently I have been working on a story game, and I have a problem with a winner leaderboard, I dont have any idea on how to do that.
I have a winner leaderboard but to make it count, you have to touch a part and I dont want to use that
I want it to get call when the story ends

Thanks, hope someone know how to do this!

1 Like

You can store the Winners in a table, and whenever the story ends, check if theyre still in the game, and reward each of them.

1 Like

How to do that? I haven’t learned anything about table

im a little confused? do you already have code? you say you already have leaderboard and you touch a part to give a win, just convert code to when the story ends, for loop through all players then award a win and then save the leaderboard

1 Like

I already have it, its right here:

local ods = game:GetService("DataStoreService"):GetOrderedDataStore("Wins")
local Players = game:GetService("Players")

local primaryColor = Color3.new(1,1,1)
local secondaryColor = Color3.new(0.815686, 0.815686, 0.815686)

local function cleanBoard()
	for _,surfaceGui in pairs(script.Parent:getChildren()) do
		if surfaceGui.Name == "SurfaceGui" then
			for _,frame in pairs(surfaceGui.ScrollingFrame:GetChildren()) do
				if frame:IsA("Frame") then
					frame:Destroy()
				end
			end
		end
	end
	
end

function updateBoard(data)
	for i,v in pairs(data) do
		for _,surfaceGui in pairs(script.Parent:GetChildren()) do
			if surfaceGui.Name == "SurfaceGui" then
				local pos = i
				local userId = v.key
				local score = v.value
				local frame = script.Frame:Clone()
				frame.Parent = surfaceGui.ScrollingFrame
				pcall(function ()
					frame.name.Text = Players:GetNameFromUserIdAsync(userId)
				end)
				pcall(function ()
					frame.playerImage.Image = Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
				end)
				frame.value.Text = score
				frame.rank.Text = "# " .. pos
				if i % 2 == 0 then
					frame.BackgroundColor3 = primaryColor
				else
					frame.BackgroundColor3 = secondaryColor
				end
				if i == 1 then
					frame.BackgroundColor3 = Color3.new(255/255, 255/255, 179/255)
					frame.name.TextStrokeColor3 = Color3.new(255/255, 226/255, 0)
					frame.value.TextStrokeColor3 = Color3.new(255/255, 226/255, 0)
					frame.rank.TextStrokeColor3 = Color3.new(255/255, 226/255, 0)
					frame.name.TextStrokeTransparency = 0
					frame.value.TextStrokeTransparency = 0
					frame.rank.TextStrokeTransparency = 0
				end
			end
		end
	end	
end

while true do
	local success, message = pcall(function()
		local pages = ods:GetSortedAsync(false,100)
		-- get data for first board
		local data = pages:GetCurrentPage()
		cleanBoard()
		updateBoard(data)
	end)
	
	if not success then
		print(message)
	end
	wait(60)
end

And I watch this video:

Forgot about the code when touching the part:

local dataStore = game:GetService("DataStoreService"):GetOrderedDataStore("Wins")

local debounce = false

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if debounce == false then
			debounce = true
			local character = hit.Parent
			local player = game.Players:GetPlayerFromCharacter(character)

			dataStore:IncrementAsync(player.UserId, 1)
			
			wait(.5)
			
			debounce = false
		end	
	end
end)
1 Like

ok so when the story ends do:

--assuming all players are winners at end of story
for index, player in pairs (game.Players:GetPlayers()) do
dataStore:IncrementAsync(player.UserId, 1)
end
2 Likes

Ah I got it, thank you so much!

function AddWins()
for _, Player in pairs(game.Players:GetChildren()) do
spawn(function()
DataStoreService:IncrementAsync(Player.UserId, 1)
end)
end
EndEvent:FireAllClients()
end