I have not a single clue how to do this, but I’ve attempted it.
local PreformerTeam = game.Teams.Preformer
local AudienceTeam = game.Teams.Audience
local EntryCard = game.ReplicatedStorage.EntryCard
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local StarterPack = game.StarterPack
if player.Team == AudienceTeam then
Random.player.Team == PreformerTeam
end
end)
end)
I know this is not correct at all but I can’t find a way to do it.
what is this?! If you want to select a random team, you need to use math.random. And can you PLEASE explain in more detail what you are trying to do, and what each variable does or stands for.
Using only math.random would not benefit him in this scenario.
What I would do is select players from a preset table; the math.random would be used to find the position in the table. Then, the script must find that player’s team and change it.
local PreformerTeam = game.Teams.Preformer
local AudienceTeam = game.Teams.Audience
local EntryCard = game.ReplicatedStorage.EntryCard
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local Players = game.Players:GetPlayers()
local Randomplayer = Players[math.random(1, #Players)]
local StarterPack = game.StarterPack
if player.Team == AudienceTeam then
Randomplayer.Team == PreformerTeam
end
end)
end)
What you’re doing here is incorrectly concatenating:
local Randomplayer = Players[math.random(1, #Players)]
You should remove the Players ahead of it.
You’re also not finding the player: you’re finding the position of the player in queue. You should use table.find to find the player in the position value.
local Teams = game:GetService("Teams"):GetTeams()
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
local random = math.random(#Teams) -- a random number between 1 and the number of teams in the game
player.Team = Teams[random] -- set the team to Teams[n] or the nth Team , where n is a random number
print(player.Team)
end)
This would put a player in a random team each time they join, remember to keep each team’s TeamColor property unique
edit: for a random player , just get a random team as I did above and set the random player’s team to the that random team.
But how do I make a random player go to a specific team?
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local Players = game.Players:GetPlayers()
local Randomplayer = math.random(1, #Players)
local StarterPack = game.StarterPack
if player.Team == AudienceTeam then
Randomplayer.Team == PreformerTeam
end
end)
end)