Change Team After Some Time

So I’m looking to make some simple wanted system so when player prompt robbery he changes team on Criminal, but I want him to go back to Citizen team after some time, how do I do that?

You can change a players team by doing:

player.Team = game.Teams.TeamName

This will change the players team to any team you would like. Also, I believe this works on scripts only.

Here is a link if you have further questions: Changing a player's team

If I am wrong, feel free to correct me! :smiley:

Edit: I just realised my mistake: You can do task.wait(time) have the player goes on criminal team.

we can change the player team to criminal if they’re not already and use a task library to task delay something like this

local Teams = game:GetService("Teams")
local Players = game:GetService("Players")

local TeamData = {
    Citizen = Teams.Citizen,
    Criminal = Teams.Criminal,
    WantedTime = 60
}

local function handleRobbery(player)
    if player.Team ~= TeamData.Criminal then
        player.Team = TeamData.Criminal
        task.delay(TeamData.WantedTime, function()
            if player.Team == TeamData.Criminal then
                player.Team = TeamData.Citizen
            end
        end)
    end
end

-- for example
local function onPlayerActivatedRobbery(player)
    handleRobbery(player)
end

--  game.ReplicatedStorage.RobberyEvent.OnServerEvent:Connect(onPlayerActivatedRobbery)  etc

I know to change team, but I need script that will for let’s say 10 seconds change players team if he is on team Criminal it will change him to Citizen.

Could you explain it to me what to do, where to put it or what to create, as I’m not really good with these types of scripts.

imma add some comments for you to help u understand more

local Teams = game:GetService("Teams") -- teams service, self-explanatory
local Players = game:GetService("Players") -- again, self-explanatory

local TeamData = {
    Citizen = Teams.Citizen, -- path for the citizen team
    Criminal = Teams.Criminal, -- path for the criminal team
    WantedTime = 60 -- amount of time you're wanted until you change teams
}

local function handleRobbery(player)
    if player.Team ~= TeamData.Criminal then -- checking if player isn't in the criminal team
        player.Team = TeamData.Criminal -- setting the players team to criminal
        task.delay(TeamData.WantedTime, function() -- waiting 60 seconds
            if player.Team == TeamData.Criminal then -- still checking if player is in the criminal team
                player.Team = TeamData.Citizen -- setting the players team to citizen
            end
        end)
    end
end

-- for example
game.ReplicatedStorage.RobberyEvent.OnServerEvent:Connect(handleRobbery) -- assuming RobberyEvent (which is a remote event) is parented to ReplicatedStorage
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.