WebNovels

Chapter 95 - code 8

local Players = game:GetService("Players")

-- Example data: playerScores[player.UserId] = score

local playerScores = {}

-- Event participation tracking

local participants = {}

-- Function to add player score during event

function AddPlayerScore(player, score)

playerScores[player.UserId] = (playerScores[player.UserId] or 0) + score

participants[player.UserId] = player

end

-- Function to distribute rewards after event

function DistributeRewards()

-- Convert scores to sortable list

local scoreList = {}

for userId, score in pairs(playerScores) do

table.insert(scoreList, {UserId = userId, Score = score})

end

-- Sort descending by score

table.sort(scoreList, function(a, b) return a.Score > b.Score end)

-- Reward top 3 players

for rank = 1, 3 do

local entry = scoreList[rank]

if entry then

local player = Players:GetPlayerByUserId(entry.UserId)

if player then

if rank == 1 then

GrantSkin(player, "RareOlympicSkin")

GrantBobux(player, 10000)

elseif rank == 2 then

GrantSkin(player, "SpecialOlympicSkin2")

GrantBobux(player, 5000)

elseif rank == 3 then

GrantSkin(player, "SpecialOlympicSkin3")

GrantBobux(player, 2500)

end

NotifyPlayer(player, "Congrats! You placed #" .. rank .. " and earned your rewards!")

end

end

end

-- Reward participation

for userId, player in pairs(participants) do

if player then

GrantBobux(player, 500)

GrantBadge(player, "OlympicParticipant")

NotifyPlayer(player, "Thanks for participating! You earned 500 Bobux and a badge.")

end

end

end

-- Placeholder functions for granting rewards and notifications

function GrantSkin(player, skinName)

-- Implement your skin granting logic here

end

function GrantBobux(player, amount)

-- Implement bobux adding logic here

end

function GrantBadge(player, badgeName)

-- Implement badge awarding logic here

end

function NotifyPlayer(player, message)

-- Implement in-game notification logic here (e.g., popup, chat message)

end

More Chapters