✓ Accepted answer
First off, you are using "==" to compare your random numbers, which won't work, as the numbers generated are never actually whole. They way to do this is to check if the generated number is less than or greater than the midpoint of the range, which is usually 0-1, so a midpoint of 0.5. Secondly, you need a separate script on the server to actually assign teams. I've done that for you here:
In your localScript:
math.randomseed(tick())
local replicatedStorage = game:GetService("ReplicatedStorage")
local ti = script.Parent.timeleft
function timeleft()
for i = 10, 0, -1 do
wait (1)
ti.Text = "Time Left: " .. i ..""
if i == 0 then
ti.Text = "Times Up! Selecting Team For You..."
local chooseteam = math.random()
if chooseteam <= .5 then
replicatedStorage:WaitForChild("PickTeam"):FireServer("Blue Team")
elseif chooseteam >= .5 then
replicatedStorage:WaitForChild("PickTeam"):FireServer("Red Team")
end
end
end
end
timeleft()
In a server script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local pickTeamEvent = Instance.new("RemoteEvent", replicatedStorage)
pickTeamEvent.Name = "PickTeam"
local pickingTeam = Instance.new("Team", game:GetService("Teams"))
pickingTeam.TeamColor = BrickColor.new("Dark stone grey")
pickingTeam.Name = "Picking Team"
local redTeam = Instance.new("Team", game:GetService("Teams"))
redTeam.TeamColor = BrickColor.new("Really red")
redTeam.Name = "Red Team"
local blueTeam = Instance.new("Team", game:GetService("Teams"))
blueTeam.TeamColor = BrickColor.new("Really blue")
blueTeam.Name = "Blue Team"
function AssignTeam(player, team)
if team == "Red Team" then
player.Team = redTeam
elseif team == "Blue Team" then
player.Team = blueTeam
end
print("Assigned Team!")
end
pickTeamEvent.OnServerEvent:connect(AssignTeam)
What happens here is that while the localscript is counting down from 10, the server creates a RemoteEvent which takes the player, and team you want to assign them to and does it. You only want to create and modify things in a server script, to work with FilteringEnabled. When the client's team is chosen in the localScript, this event is fired and the server assigns the player to one of the created teams. Simple!
If I've helped you, make sure to mark my answer correct :)
1 comment
In order to change the team a player is on, you need to change the TeamColor property of the player.