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
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.
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âŚ
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)
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.
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)
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
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.
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.