How to give 2 roles for only 2 players, then give the third role everyone else?

  1. What do you want to achieve? Keep it simple and clear!
    I want to learn how to pick 1 role for a player, and another for a second player, then give the third role everyone else

  2. What is the issue? Include screenshots / videos if possible!
    Well, i tried through the tables, i dont know how to do that. I tried with remote events, and it gives 1st ,2nd and 3rd role the first 3 players, then the next three, and over and over.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yes, I did but still couldnt find anything, i even tried on other sites, neither of them worked…

Please help me i had this issue 2 months now, still couldnt find a solution, I got the member role just today so now im trying dev forum to see if someone will help…

1 Like

Don’t know what you mean by roles but here:

game.Players.PlayerAdded:Connect(function(plr)
local role1taken = false
local role2taken = false

local role1 = role1
local role2 = role2
local role3 = role3

for i,v in pairs(game.Players:GetPlayers()) do


if  role1taken == false then
local newrole1 = role1:Clone()
newrole1.Parent = v
role1taken = true -- marking role2 is taken by a player
return end

if role2taken = false then
local newrole2 = role2:Clone()
newrole2.Parent = v
role2taken = true -- marking role2 is taken by a player
return end

local newrole3 = role3:Clone()
newrole3.Parent = v

  end
end)
1 Like

By roles i meant like a detective a hunter and a victim, i dont know just an example.

Then here you go, I gave you an answer

Ok, i will try that now. I will mark it as a solution if it works.

Another thing, this should be a local script right?

No, it should be a server script…
You cannot visualize it yet, the scripts only puts values in the players, YOU will have to script the visualizer for the roles, also, you have to put “role1” as a value.

I didn’t do anything but show an example…

1 Like

Ok, i was just checking. Because i still didnt learn whether this should be a local or a server script.

Hmm looks like it doesnt work, everyone becomes the 3rd role which i dont want.

use this code i hope it work:

if u have any problem just reply to my reply

local Players = game.Players:GetPlayers() -- getting all players

local Role1 = "VIP" -- role 1 for the player u want
local Role2 = "PREMIUM" -- role 2 for the player u want

local role1player = "Someone" -- the player gonna get role 1
local role2player = "Someone's friend" -- the player gonna get tole 2

function giveRole() -- getting role
      for i, player in pairs(Players) do
            if player.Name = role1player then
                  player.role.Value = Role1
            elseif player.Name = role2player then
                  player.role.Value = Role1
            else
                  player.role.Value = "A guest that wont get a role so choose any u want"
            end
      end
end)

But i need to choose a random player, not a player so he can be the same role every round…

In this case, I used Murderer Mystery as an example.

local players = game:GetService("Players");


local function insertTag(plrs, tagName)
    for index, plr in pairs(plrs) do
        if plr:FindFirstChild(tagName) then return end
        
        local tag = Instance.new("StringValue")
        tag.Name = tagName
        tag.Parent = plr
        
    end
    
end

local function giveRoles()

    local contestants = {};
    local victims = {}

    local murderer;
    local sheriff;

    for index, player in pairs(players:GetPlayers()) do
        if player then
            table.insert(contestants, player)
        end
    end

    murderer = contestants[math.random(#contestants)]

    for index, player in pairs(contestants) do
        if not player then
            table.remove(contestants, index)
        end

        if player == murderer then
            table.remove(contestants, index)
            break
        end
    end

    sheriff = contestants[math.random(#contestants)]

    for index, player in pairs(contestants)  do
        if not player then
            table.remove(contestants, index)
        end

        if player == sheriff then
            table.remove(contestants, index)
            break
        end
    end

    for index, player in pairs(contestants) do
        if not player then table.remove(contestants, index) end

        if player then
            table.insert(victims, player)
        end
    end
    contestants = {}
    
    insertTag(victims, "Victim")
    
    insertTag({murderer}, "Murderer")
    
    insertTag({sheriff}, "Sheriff")
    

    -- So, murderer is a random player;
    -- Sherrif is a different player;
    -- Victims are other players;

end

So you mean like murder mystery with a Sheriff Murderer and everyone else.
(This is for everyone else with any confusion btw lol)

Well, yes. Just different.

I need to type this so i can send this message.

Ok so i have remote events which i need to fire when the role for a specific player is chosen, where do i put the code to fire the events?

Make a list of values corresponding to players in the current game. Use a function ran once to pull out a random value and put it in some other designated object (folder, model, etc…). Use this again for “sheriff” or however many single-roles you want. If you want let’s just say, two sheriffs, you would run the function twice; make a for loop to do so.

On an alternate idea when the round starts, make a script that finds the player with the value correspondence, and changes their TeamColor or Team, to the one you may have created in “game.Teams.” For the leftover players, just assign them as well.

Doing it around this idea would allow for you to make a “side-line” or “AFK” system, where players can choose to ‘opt-out’ of the game, and remove their playing “value” from the list.

What @XXgamerisaliveXx did works, now i am asking him where do i put the code to fire the remote events for that player.

We can’t tell you everything. You just asked how to give roles.

Basically this is the same topic, i need that to make my roles work, and i cant give weapons nor show the player what role he is if i dont fire the events

@Ancientcub @NoobExams @XXgamerisaliveXx Please do NOT spoonfeed.

@OP, what I suggest is have a table which lists who got a role already. For example, if Player 1 got murderer and his/her name is not in the table, then you will allow Player 1 to be murderer.

1 Like