I Want a Round System that teleports players and also sets their team to “Playing” from the “Lobby” team and not the “AFK” or “Playing” Team (and also vice versa when the game is over
The Script teleports me even when i am in the “AFK” Team
I have searched everywhere but i couldn’t find anything that helped.
My Script:
for i, v in pairs(game.Teams.Lobby:GetPlayers()) do
local Character = v.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
if Character then
HumanoidRootPart.CFrame = ClonedMap.TeleportPoint.CFrame
wait(2)
v.Team = playingteam
end
end
for i, v in pairs(game.Teams.Lobby:GetPlayers()) do
local Character = v.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
if Character and v.Team.Name ~= "AFK" then
HumanoidRootPart.CFrame = ClonedMap.TeleportPoint.CFrame
wait(2)
v.Team = playingteam
end
end
It doesn’t look like you put an “end” to end the if then statement, and I also don’t think you checked the player team at all which can be done by adding
and v.Team.Name ~= “AFK”
to the if then statement. Also, the wait(2) doesn’t look to be inside of the if then statement.
--Variables
local Lobby = game.Workspace.Lobby
local Maps = game.ReplicatedStorage.Maps:GetChildren()
local Disasters = game.ReplicatedStorage.DisasterRemotes:GetChildren()
local Status = game.ReplicatedStorage.Status
local lobbyteam = game.Teams.Lobby
local playingteam = game.Teams.Playing
local afkteam = game.Teams.AFK
local intermission = 10
local gameLength = 60
-- Game Loop
while true do
-- intermission
for i = intermission, 0, -1 do
Status.Value = "Intermission: "..i
task.wait(1)
end
-- Map Selector
local ChosenMap = Maps [math.random(1, #Maps)]
local ClonedMap = ChosenMap:Clone()
ClonedMap.Parent = game.Workspace.SelectedMap
Status.Value = "Map: "..ClonedMap.Name
task.wait(1)
-- Teleports to the map
for i, v in pairs(game.Players:GetPlayers()) do
local Character = v.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
if Character and v.Team.Name ~= "AFK" then
HumanoidRootPart.CFrame = ClonedMap.TeleportPoint.CFrame
v.Team = playingteam
end
end
-- Random Disaster
local ChosenDisaster = Disasters [math.random(1, #Disasters)]
local hint = game.ReplicatedStorage.Hint
local hintevent = game.ReplicatedStorage.HintEvent
local risingevent = game.ReplicatedStorage.DisasterRemotes.RisingLava
local tsunamievent = game.ReplicatedStorage.DisasterRemotes.Tsunami
local meteorevent = game.ReplicatedStorage.DisasterRemotes.Meteor
if ChosenDisaster == game.ReplicatedStorage.DisasterRemotes.Tsunami then
tsunamievent:Fire()
gameLength = 30
print("The game has started (Rising Lava)")
wait(5)
hint.Value = "A Tsunami has been spotted! Seek hight shelter immediately!"
hintevent:FireAllClients()
print("The game has started (Tsunami)")
elseif ChosenDisaster == game.ReplicatedStorage.DisasterRemotes.Meteor then
meteorevent:Fire()
gameLength = 45
print("The game has started (Rising Lava)")
risingevent:Fire()
wait(5)
hint.Value = "A Meteor Shower has been spotted! Seek shelter immediately, and avoid getting hit!"
hintevent:FireAllClients()
elseif ChosenDisaster == game.ReplicatedStorage.DisasterRemotes.RisingLava then
risingevent:Fire()
gameLength = 45
print("The game has started (Rising Lava)")
wait(5)
hint.Value = "Rising Lava has been spotted! Seek high shelter immediately!"
hintevent:FireAllClients()
end
task.wait(5)
-- Game Time
for i = gameLength, 0, -1 do
Status.Value = "Game: "..i
task.wait(1)
Status.Value = "Game Over"
end
local playingplayers = playingteam:GetPlayers()
for i, player in pairs (playingplayers) do
player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1
local Character = player.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
if Character then
HumanoidRootPart.CFrame = Lobby.TeleportPoint.CFrame
wait(1)
player.Team = lobbyteam
end
end
-- Destroys Map
wait(3)
ClonedMap:Destroy()
end
Try to check the condition maybe, perhaps add a check if it is lobby.
print(v)
print(v.Team.Name)
print(v.Team.Name ~= "AFK")
if Character and v.Team.Name ~= "AFK" and v.Team.Name == "lobby" then
HumanoidRootPart.CFrame = ClonedMap.TeleportPoint.CFrame
v.Team = playingteam
end
local lobbyteam = game:GetService("Team").Lobby
local playingteam =game:GetService("Team").Playing
local afkteam = game:GetService("Team").AFK
for _, v in pairs(lobbyteam:GetPlayers()) do
local Character = v.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
if Character then
HumanoidRootPart.CFrame = game.Workspace.ClonedMap.TeleportPoint.CFrame
v.Team = playingteam
end
end
You don’t have to use:
v.Team.Name
You should just use:
v.Team
Also, not sure if you’ve updated your code to use the players from the lobby team and not all the players in general, because you did:
for i, v in pairs(game.Players:GetPlayers()) do
When it should be
for i, v in pairs(lobbyteam:GetPlayers()) do
Lastly, when defining variables that are services you should use GetService(), for example:
game:GetService("Team")
then you can define a team like this:
local lobbyteam = game:GetService("Teams").Lobby
If this still doesn’t work, if you have errors please post it. Also make sure the lobby team is auto assignable and every other team has auto assignable turned off. That way, players who join are automatically assigned to the lobby team.
You could create a new function that returns true if the player is in the “Playing” or “AFK” teams. Then you could use that function as a condition in your for loop to only teleport Lobby players.
Example: local function isPlayingOrAFK(player)
return player.Team == playingTeam or player.Team == afkTeam
end
for i, v in pairs(game.Teams.Lobby:GetPlayers()) do
if not isPlayingOrAFK(v) then
local Character = v.Character
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
if Character then
HumanoidRootPart.CFrame = ClonedMap.TeleportPoint.CFrame
wait(2)
v.Team = playingTeam
end
end