Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.2 kB
0
Indexable
Never
-- Nightlight Tag Game Script

local Players = game:GetService("Players")
local light = game.Workspace.Nightlight -- Nightlight object in the workspace
local tagger = nil

-- Function to handle player tagging
local function tagPlayer(player)
    if player ~= tagger then
        tagger = player
        print(player.Name .. " is now it!")
    end
end

-- Function to handle player touches
local function onTouch(hit)
    local character = hit.Parent
    local player = Players:GetPlayerFromCharacter(character)
    if player then
        tagPlayer(player)
    end
end

-- Connect touch function to Nightlight object
light.Touched:Connect(onTouch)

-- Main game loop (optional, you can use events or other triggers)
while true do
    wait(1) -- Check every second (adjust as needed)

    -- Check if there is a winner (all players are tagged except one)
    local untaggedCount = 0
    for _, player in ipairs(Players:GetPlayers()) do
        if player ~= tagger then
            untaggedCount = untaggedCount + 1
        end
    end

    if untaggedCount <= 1 then
        -- Declare the winner
        print("Game over! " .. tagger.Name .. " wins!")
        break
    end
end