Random Role Giver

Alright, to begin this with, I’m trying to make somewhat of a “Murder Mystery 2” but with my version. I found this very cool tutorial from youtube by HowToRoblox

The thing that I want to achieve was located at the end of the video. Well here’s my problem.

local roles = 
	{
		Murder = {1, Color3.fromRGB(221, 29, 29), script.Knife};
		Sheriff = {1, Color3.fromRGB(22, 120, 240), script.Gun};
		Civilian = {100, Color3.fromRGB(62, 197, 32)}
	}

local rolesTable = {"Murder", "Sheriff", "Civilian"}


function handleGui(plr, pickedRole, weapon)
	
	for i, player in pairs(game.Players:GetPlayers()) do
		local gui = player.PlayerGui.Picker
		gui.Enabled = true

		for x = 1, 10 do

			local randomRole = rolesTable[math.random(1, #rolesTable)]

			gui.Background.RoleGiven.TextColor3 = roles[randomRole][2]
			gui.Background.RoleGiven.Text = randomRole

			wait(0.2)
		end

		gui.Background.RoleGiven.TextColor3 = roles[pickedRole][2]
		gui.Background.RoleGiven.Text = pickedRole

		if weapon then
			weapon:Clone().Parent = player.Backpack
		end

		wait(2)
		gui.Enabled = false	
	end
end

So, everytime my pre-installed intermission system was done, it was meant to run this random picker script. But the problem is, it says that in the line

gui.Background.RoleGiven.TextColor3 = roles[pickedRole][2]
		gui.Background.RoleGiven.Text = pickedRole

Attempt to index nil with number.

I tried to solve it myself but I can’t. Please do help me if possible, thanks.

Where is pickedRole coming from? Also, consider that Sheriff is spelt differently in the roles table and the table called rolesTable. Maybe that’s the source of some issue?

What this issue means to me is just that roles[pickedRole] isn’t returning what you expect it to. Maybe print roles[pickedRole] and see what it outputs. If nothing, it changes to a matter of where the disconnect is stemming from.

pickedRole was a parameter for what role the player will gets. (Based of the video)

What line is supplying it to your function handleGui though? Its second argument is pickedRole.

Tried to print the pickedRole and it printed nil, great.

What line is calling this function?

Basically; show how you are calling the handleGui function;
pickedRole is nil, and plr is basically unused (since you are running a for loop again), are you sending the pickedRole in plr’s place?

You should probably do print(plr,pickedRole,weapon) to see what went wrong.