I don’t really know what the Title should be since I can’t really describe it much. Anyway Im creating a script which Selects different people to have different roles for Say. Somebody may be a Medic someone else may be a Swordsman or Guard.
local Select = Instance.new("StringValue")
local Z = Select:Clone()
repeat RandomPlayer = players [math.random(1, #players)] until RandomPlayer:FindFirstChild("Value") == nil
Z.Value = Table [math.random(1, #Table)]
The script should take every player and give it a role. However instead of doing it to everyone it does it to only one person. I have a good idea why it does this I can’t think of a solution.
You could loop through the players and check if they have a team and if they don’t then choose a random one that has not been taken then assign it to the player (not the best way)
I’m not very sure of the problem your having but if your looking to give a random role to a player that joins I think this should do it
local Players = game:GetService("Players") -- Players Service
local Roles = {"Role1","Role2"} -- The roles that are available for the players
Players.PlayerAdded:Connect(function(plr) -- Function Connects when Player joins
local Select = Instance.new("StringValue",plr) -- Create the Role String Value
Select.Name = "Role" -- Give it a Name
Select.Value = Roles[math.random(1,#Roles)] -- Give the Role to the player
end)
You are setting a random player’s value to something until that same player’s value is something.
My suggestion is, use for loops.
for _,Player in pairs(game:GetService("Players"):GetPlayers()) do
local Select = Instance.new("StringValue")
Select.Parent = Player
Select.Value = Table[math.random(1,#Table)]
end
You can add a role to a player on joined using this reply.