Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make someone be sheriff or innocent or murder?

So this isn't my whole script this is just what I came up with to make this idea. So what I am trying to do is pick 1 player for murder and sheriff and the rest of the players innocent also I am firing there client only so nobody else can see it and I am changing it on a text label..

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

	math.random(1,#players)--picking 1 player
			remote:FireClient(players, "You are a Sherif") -- Firing only their client and saying you are sheriff on there text label
			
			math.random(1,#players)
			remote:FireClient(players, "You are a Murder")
			
			math.random(#players)
			remote:FireClient(players, "You are a innocent")  --Dont need only 1 player for innocent the rest of the people are just innocent.

1 comment

0

Use a generic for loop on line 10. Also, I do recommend removing each player respectively that you've already chosen on line 3 and 6, so you don't have someone being the Sheriff and the Murderer at the same time.

1 answer

"Your" code isn't something over the top but I can already see some things you won't need (which you gracefully pointed out) but I guess I'll just show you my method of solving this easy to fix issue.

All you have to do is keep track of the Sherif and Murder meanwhile everyone else can just receive the default text message. You can do other crazy stuff like "chance of being murder" or something to this later if you want but I'll keep it simple. I'll also set it up as a function in case you want to choose a sheriff and murder again.

Try something like this (I provided some useful notes in there too!):

players = game.Players:GetPlayers() --You don't need "local" unless it's within a function or something similar

function message(Chosen, PlayerNum)
	if PlayerNum == Chosen[1] then
		return "You are a Sheriff"
	elseif PlayerNum == Chosen[2] then
		return "You are a Murder"
	else
		return "You are innocent"
	end
end

function chosePlayers()
	local Chosen= {} --The first part of the table will be the Sherif and the other one will be the Murder
	
	Chosen[1] = math.random(1, #players) --This will be the sheriff and no special action is needed since it doesn't have to avoid anyone
	repeat wait() Chosen[2] = math.random(1, #players) until Chosen[2] ~= Chosen[1] and Chosen[2] ~= nil --Basically keeps on randomly chosing players until the murder isn't the sheriff or nobody

	for i, v in pairs(1, #players) do
		remote:FireClient(v, message(Chosen, i)) --"v" is the chosen player while "i" is which player it is in a numbered list. They all go to the message function.
	end
end --This is the function that chooses a random sheriff and murder

If you have any questions or issues, please contact me. ;)

3 comments

0

Sorry if something doesn't work, I'm trying to fix my studio to check for any issues but it's taking a bit longer than I expected.

0

lol the roblox site is down studio wont work properly

0

Why do you use FireClient in loop if you can use FireAllClients?

This discussion is preserved as it was. New answers, comments, and votes are closed.