Round Script System

·

·

Leaderboard Round Script Roblox

-- Script to create a leaderboard (This should be placed in ServerScriptService)
game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local wins = Instance.new("IntValue")
    wins.Name = "Wins"
    wins.Value = 0
    wins.Parent = leaderstats
end)

Round Script

 local startButton = script.Parent -- The button that starts the round
local lobbySpawn = game.Workspace.LobbySpawn -- Spawn location in the lobby
local taskSpawn = game.Workspace.TaskSpawn -- Spawn location in the task area
local taskButton = game.Workspace.TaskButton -- The button that needs to be clicked to complete the task

local roundActive = false

local function startRound(player)
    if roundActive then return end
    roundActive = true

    -- 10 second delay before teleportation
    wait(10)

    -- Teleport the player to the task area
    player.Character:SetPrimaryPartCFrame(taskSpawn.CFrame)

    -- Start the task timer
    local taskTimer = 100
    local taskCompleted = false

    -- Task button click event
    local function onTaskButtonClicked()
        if taskCompleted then return end
        taskCompleted = true
        -- Increment the player's wins
        local wins = player:FindFirstChild("leaderstats"):FindFirstChild("Wins")
        if wins then
            wins.Value = wins.Value + 1
        end
        -- Teleport player back to the lobby
        player.Character:SetPrimaryPartCFrame(lobbySpawn.CFrame)
        roundActive = false
    end

    taskButton.ClickDetector.MouseClick:Connect(onTaskButtonClicked)

    -- Wait for the task time to finish
    wait(taskTimer)

    -- If task is not completed, teleport the player back to the lobby
    if not taskCompleted then
        player.Character:SetPrimaryPartCFrame(lobbySpawn.CFrame)
        roundActive = false
    end
end

-- Start round when the button is clicked
startButton.ClickDetector.MouseClick:Connect(function(player)
    startRound(player)
end)