So I making a training facility and im trying to make a button that randomize players into different teams. Can some on help me?
Server Script:
local rs = game.ReplicatedStorage.TeamEvent
local team1 = game.Teams.Team1
local team2 = game.Teams.Team2
rs.OnServerEvent:Connect(function()
game.Players.PlayerAdded:Connect(function(player)
local randomTeam = team1 and team2
player.Team = randomTeam
end)
end)
Local Script:
local button = script.Parent
local rs = game.ReplicatedStorage.TeamEvent
button.MouseButton1Click:Connect(function()
rs:FireServer()
end)
local teams = game.Teams:GetChildren() --GetChildren returns an array
--getting a random index using the built-in pseudorandom function
local index = math.random(1, #teams)
local randomTeam = teams[index] --indexing the array/table with that specific index
player.Team = randomTeam
Are you trying to randomly generate players evenly across the different teams or just randomly generate them onto different teams? If you’re trying to generate them randomly without it being dispersed evenly you can generate a number between 0 and 1 and if the number is greater than 0.5 they will be put onto a Team 2 and if its lower they get put on Team 1.