For some reason I can’t transfer teams with this script
local TeamColors = {
["TeamRed"] = BrickColor.new("Really red"),
["TeamBlue"] = BrickColor.new("Really blue")
}
-- Function to assign a player to a team
local function assignTeam(player, teamName)
local team = game:GetService("Teams"):FindFirstChild(teamName)
if team then
player.Team = team
player.TeamColor = TeamColors[teamName]
print(player.Name .. " has been assigned to " .. teamName)
else
warn("Team " .. teamName .. " does not exist.")
end
end
-- Event: Player added
game.Players.PlayerAdded:Connect(function(player)
-- Event: Chat message received
player.Chatted:Connect(function(message)
if message:lower() == "/blue" then
assignTeam(player, "TeamBlue")
elseif message:lower() == "/red" then
assignTeam(player, "TeamRed")
end
end)
end)
I am not sure if this script
-- Event: Gameplay loop
game:GetService("RunService").Stepped:Connect(function()
if not MatchStarted then
MatchStarted = true
-- Disable the TeamChangeListener script
game.ServerScriptService.TeamChangeListener.Disabled = true
wait(7) -- Duration of the match
print("Match ended!")
-- Store the match message instance
MatchMessage = Instance.new("Message", game.Workspace)
MatchMessage.Text = "Match has ended. All players going back to their previous position."
MatchMessage:Destroy()
-- Move all players to the default position
for _, player in ipairs(game.Players:GetPlayers()) do
player.Character.HumanoidRootPart.CFrame = CFrame.new(2.6, 0.5, -2.3)
end
wait(10) -- Duration of the lobby until the match starts again
print("Lobby Started")
-- Enable the TeamChangeListener script
MatchStarted = false
game.ServerScriptService.TeamChangeListener.Disabled = false
local msg2 = Instance.new("Message", game.Workspace)
msg2.Name = "msg2"
wait(1)
msg2.Text = "Starting match in 10 seconds"
game.ServerScriptService.TeamChangeListener.Enabled = true
wait(10)
print("Msg2 destroyed")
msg2:Destroy()
elseif MatchStarted == false then
game.ServerScriptService.TeamChangeListener.Enabled = true
print("Player can use change team")
end
end)
``` Is interfering with it.
On these lines
for _, player in ipairs(game.Players:GetPlayers()) do
player.Character.HumanoidRootPart.CFrame = CFrame.new(2.6, 0.5, -2.3)
end
wait(10) -- Duration of the lobby until the match starts again
print("Lobby Started")
-- Enable the TeamChangeListener script
MatchStarted = false
game.ServerScriptService.TeamChangeListener.Disabled = false
local msg2 = Instance.new("Message", game.Workspace)
msg2.Name = "msg2"
wait(1)
msg2.Text = "Starting match in 10 seconds"
game.ServerScriptService.TeamChangeListener.Enabled = true
wait(10)
print("Msg2 destroyed")
msg2:Destroy()
elseif MatchStarted == false then
game.ServerScriptService.TeamChangeListener.Enabled = true
print("Player can use change team")
end
end)
The player can use team doesnt print.
local MatchMessage = nil
-- Define team colors
local TeamColors = {
["TeamRed"] = BrickColor.new("Really red"),
["TeamBlue"] = BrickColor.new("Really blue"),
["Neutral"] = BrickColor.new("Institutional white")
}
-- Function to assign a position and color to a player
local function assignPosition(player)
local teamName = player.Team.Name
-- Only assign position if the match has not started
if not MatchStarted then
-- Create a new part for the player's position
local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.Transparency = 0.5
part.Size = Vector3.new(5, 5, 5)
-- Set the position based on team
if teamName == "TeamRed" then
part.Position = Vector3.new(-262.6, 1.5, 551.1) -- Position for TeamRed
elseif teamName == "TeamBlue" then
part.Position = Vector3.new(204.5, 1.5, 193.2) -- Position for TeamBlue
else
part.Position = Vector3.new(2.6, 0.5, -2.3) -- Default position for Neutral
end
part.BrickColor = TeamColors[teamName] or TeamColors["Neutral"]
part.Parent = workspace
-- Move the player to the assigned position
player.Character.HumanoidRootPart.CFrame = part.CFrame
end
end
-- Event: Player added
game.Players.PlayerAdded:Connect(function(player)
-- Assign a position to the player
assignPosition(player)
-- Event: Player team changed
player:GetPropertyChangedSignal("Team"):Connect(function()
-- Assign a new position if the player changes team
assignPosition(player)
end)
end)
-- Event: Gameplay loop
game:GetService("RunService").Stepped:Connect(function()
if not MatchStarted then
MatchStarted = true
-- Disable the TeamChangeListener script
game.ServerScriptService.TeamChangeListener.Disabled = true
wait(7) -- Duration of the match
print("Match ended!")
-- Store the match message instance
MatchMessage = Instance.new("Message", game.Workspace)
MatchMessage.Text = "Match has ended. All players going back to their previous position."
MatchMessage:Destroy()
-- Move all players to the default position
for _, player in ipairs(game.Players:GetPlayers()) do
player.Character.HumanoidRootPart.CFrame = CFrame.new(2.6, 0.5, -2.3)
end
wait(10) -- Duration of the lobby until the match starts again
print("Lobby Started")
-- Enable the TeamChangeListener script
MatchStarted = false
game.ServerScriptService.TeamChangeListener.Disabled = false
local msg2 = Instance.new("Message", game.Workspace)
msg2.Name = "msg2"
wait(1)
msg2.Text = "Starting match in 10 seconds"
game.ServerScriptService.TeamChangeListener.Enabled = true
wait(10)
print("Msg2 destroyed")
msg2:Destroy()
elseif MatchStarted == false then
game.ServerScriptService.TeamChangeListener.Enabled = true
print("Player can use change team")
end
end)
The script above, it’s purpose is to handle the match, if the matchstarted = true
then it should transfer the players to
-- Set the position based on team
if teamName == "TeamRed" then
part.Position = Vector3.new(-262.6, 1.5, 551.1) -- Position for TeamRed
elseif teamName == "TeamBlue" then
part.Position = Vector3.new(204.5, 1.5, 193.2) -- Position for TeamBlue
else
part.Position = Vector3.new(2.6, 0.5, -2.3) -- Default position for Neutral
end
But it doesn’t.
Another one here
game:GetService("RunService").Stepped:Connect(function()
if not MatchStarted then
MatchStarted = true
-- Disable the TeamChangeListener script
game.ServerScriptService.TeamChangeListener.Disabled = true
wait(7) -- Duration of the match
print("Match ended!")
-- Store the match message instance
MatchMessage = Instance.new("Message", game.Workspace)
MatchMessage.Text = "Match has ended. All players going back to their previous position."
MatchMessage:Destroy()
-- Move all players to the default position
for _, player in ipairs(game.Players:GetPlayers()) do
player.Character.HumanoidRootPart.CFrame = CFrame.new(2.6, 0.5, -2.3)
end
wait(10) -- Duration of the lobby until the match starts again
print("Lobby Started")
-- Enable the TeamChangeListener script
MatchStarted = false
game.ServerScriptService.TeamChangeListener.Disabled = false
local msg2 = Instance.new("Message", game.Workspace)
msg2.Name = "msg2"
wait(1)
msg2.Text = "Starting match in 10 seconds"
game.ServerScriptService.TeamChangeListener.Enabled = true
wait(10)
print("Msg2 destroyed")
msg2:Destroy()
elseif MatchStarted == false then
game.ServerScriptService.TeamChangeListener.Enabled = true
print("Player can use change team")
end
end)
If the match ended then game.ServerScriptService.TeamChangeListener.Enabled = true.
It does enable it but doesn’t transfer me to another team.
Heres a video
All the scripts
External Medialocal MatchStarted = false
local MatchMessage = nil
-- Define team colors
local TeamColors = {
["TeamRed"] = BrickColor.new("Really red"),
["TeamBlue"] = BrickColor.new("Really blue"),
["Neutral"] = BrickColor.new("Institutional white")
}
-- Function to assign a position and color to a player
local function assignPosition(player)
local teamName = player.Team.Name
-- Only assign position if the match has not started
if not MatchStarted then
-- Create a new part for the player's position
local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.Transparency = 0.5
part.Size = Vector3.new(5, 5, 5)
-- Set the position based on team
if teamName == "TeamRed" then
part.Position = Vector3.new(-262.6, 1.5, 551.1) -- Position for TeamRed
elseif teamName == "TeamBlue" then
part.Position = Vector3.new(204.5, 1.5, 193.2) -- Position for TeamBlue
else
part.Position = Vector3.new(2.6, 0.5, -2.3) -- Default position for Neutral
end
part.BrickColor = TeamColors[teamName] or TeamColors["Neutral"]
part.Parent = workspace
-- Move the player to the assigned position
player.Character.HumanoidRootPart.CFrame = part.CFrame
end
end
-- Event: Player added
game.Players.PlayerAdded:Connect(function(player)
-- Assign a position to the player
assignPosition(player)
-- Event: Player team changed
player:GetPropertyChangedSignal("Team"):Connect(function()
-- Assign a new position if the player changes team
assignPosition(player)
end)
end)
-- Event: Gameplay loop
game:GetService("RunService").Stepped:Connect(function()
if not MatchStarted then
MatchStarted = true
-- Disable the TeamChangeListener script
game.ServerScriptService.TeamChangeListener.Disabled = true
wait(7) -- Duration of the match
print("Match ended!")
-- Store the match message instance
MatchMessage = Instance.new("Message", game.Workspace)
MatchMessage.Text = "Match has ended. All players going back to their previous position."
MatchMessage:Destroy()
-- Move all players to the default position
for _, player in ipairs(game.Players:GetPlayers()) do
player.Character.HumanoidRootPart.CFrame = CFrame.new(2.6, 0.5, -2.3)
end
wait(10) -- Duration of the lobby until the match starts again
print("Lobby Started")
-- Enable the TeamChangeListener script
MatchStarted = false
game.ServerScriptService.TeamChangeListener.Disabled = false
local msg2 = Instance.new("Message", game.Workspace)
msg2.Name = "msg2"
wait(1)
msg2.Text = "Starting match in 10 seconds"
game.ServerScriptService.TeamChangeListener.Enabled = true
wait(10)
print("Msg2 destroyed")
msg2:Destroy()
elseif MatchStarted == false then
game.ServerScriptService.TeamChangeListener.Enabled = true
print("Player can use change team")
end
end)
This one above is responsible for all of the team position
local TeamColors = {
["TeamRed"] = BrickColor.new("Really red"),
["TeamBlue"] = BrickColor.new("Really blue")
}
-- Function to assign a player to a team
local function assignTeam(player, teamName)
local team = game:GetService("Teams"):FindFirstChild(teamName)
if team then
player.Team = team
player.TeamColor = TeamColors[teamName]
print(player.Name .. " has been assigned to " .. teamName)
else
warn("Team " .. teamName .. " does not exist.")
end
end
-- Event: Player added
game.Players.PlayerAdded:Connect(function(player)
-- Event: Chat message received
player.Chatted:Connect(function(message)
if message:lower() == "/blue" then
assignTeam(player, "TeamBlue")
elseif message:lower() == "/red" then
assignTeam(player, "TeamRed")
end
end)
end)
This one is for the team transfer.