local M=require((script.Parent:WaitForChild("\071\097\109\101 \076\111\103\105\099")).KeyModule)local function D(D)if D:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")then M.DropTools(player,game.Workspace.Map,D.HumanoidRootPart.Position)print("\084\111\111\108\115 \068\114\111\112\112\101\100")end if player:FindFirstChild("\067\111\110\116\101\115\116\097\110\116")then player.Contestant:Destroy()print("\099\111\110\116\101\115\116\097\110\116 \116\097\103 \100\114\111\112\112\101\100")elseif player:FindFirstChild("\080\105\103\103\121")then player.Piggy:Destroy()print("\112\105\103\103\121 \116\097\103 \100\114\111\112\112\101\100")end end local function e(M)M.Humanoid.Died:Connect(D)end local function k(M)local D=Instance.new("\066\111\111\108\086\097\108\117\101")D.Name="\073\110\077\101\110\117"D.Parent=M M.CharacterAdded:Connect(e)end


local keyModule = require(script.Parent:WaitForChild("Game Logic").KeyModule)

local function cleanupCharacter(char)
    
    -- drop the tools in the spot
    if char:FindFirstChild("HumanoidRootPart") then
        keyModule.DropTools(player,game.Workspace.Map,char.HumanoidRootPart.Position)
        print("Tools Dropped")
    end

    -- remove the tag from their player
    if player:FindFirstChild("Contestant") then
        player.Contestant:Destroy()
        print ("contestant tag dropped")
    elseif player:FindFirstChild("Piggy") then
        player.Piggy:Destroy()
        print ("piggy tag dropped")
    end
end

local function onCharacterAdded(char)
    -- drop all the tools that the player is holding
    char.Humanoid.Died:Connect(cleanupCharacter)
    
end

local function onPlayerAdded(player)
        -- add a tag to players when joining the game; this tag is removed when players click on 'play'
        -- prevents AFK players from joining the game
        local inMenu = Instance.new("BoolValue")
        inMenu.Name = "InMenu"
        inMenu.Parent = player    

        -- this function fires when the character spawns into the game (i.e. after the die / reset their character
        player.CharacterAdded:Connect(onCharacterAdded)
end
