Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make dead people spawn in the lobby? [closed]

Asked by
nikitala -10
3 years ago
Edited 3 years ago

So basically I want to make a PVP game with 3 teams, and one of the teams is called Lobby where all dead people are in. Can someone help me, how to make dead people spawn in lobby [team lobby]?

0
it's not request site mate, show us what you have tried and we can help you fix it, why would someone write script for you.. imKirda 4491 — 3y
0
But try using Humanoid.Died event and when it fires, try setting team of the Player to team Lobby imKirda 4491 — 3y

Marked as Duplicate by imKirda and Dovydas1118

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

This isn't a request site but I'll try to give you a basic idea to help you understand more clearly.

Addressing the players

To address each specific player, you can create two lists for 'Playing' and 'Lobby'.

Players = {}
Lobby = {}

Whenever a player joins, you can add them to the 'lobby' list and when they leave, remove them from either of the lists.

Events

game.Players.PlayerAdded:Connect(function(player)
    table.insert(Lobby,player.Name)
end)

game.Players.PlayerRemoved:Connect(function(player)
    if table.find(Lobby,player.Name) then
        table.remove(Lobby,player.Name)
    elseif table.find(Players, player.Name) then
        table.remove(Players,player.Name)
    end
end)

You can insert a block of code under the 'PlayerAdded' function to make it so that, if a player died, it would be moved into the lobby list.

player.CharacterAdded:Connect(function(Character)
    local Humanoid = Character:WaitForChild("Humanoid")

    if Humanoid then
        Humanoid.Died:Connect(function()
            if not table.find(Lobby,player.Name) then
                table.insert(Lobby,player.Name)
            end
            if table.find(Players,player.Name) then
                table.remove(Players,player.Name)
            end
        end)
    end
end)

Functions

Now we need to create a function that we can call, whenever we want to change everybody's teams like at the start of a round or at the end of a round. So we'd do:

local function ChangeAllPlayers(list,list2) -- List arguments that we can change for reliability
    for _,playerName in pairs(list) do
        if game.Players:FindFirstChild(playerName) then
            local success,error = pcall(function() -- In case of glitches
                table.remove(list,playerName)
                table.insert(list2,playerName)
            end)
        end
    end
end)

To run code for each specific 'team', you can address the list and use a 'for i,v' loop to loop and iterate through the player names. You can slightly alter the code to make it store the actual player object rather than their names.

In my opinion, it is better to make it so that there are no teams for people who are in lobby and/or playing as it looks and seems more professional, but if you want to make it work with teams, you can slightly alter the code, as well.

You should learn more about working with loops and using Player service, and you can do so by reading up here!

Next time, I highly suggest you try to formulate your own code before asking. Again, this is not a request site, but I'm feeling nice today.

Ad