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

How do I make this part of my script detect who the murderer is and give them this weapon?

So I am trying to write a script that essentially goes through the player list and decides who is a "Murderer" and "Detective". My problem is with a section of the code that is not working for some reason. Any help would be appreciated.

The code below is supposed to give the murderer a sword, but it is completely ignoring the "if x == v then" portion.

		local Murderer = math.random(1,#Playing)
		local Man = ""
		for i,v in pairs(Playing) do
			if i == Murderer then
				Man = v
				print(v.." is the murderer!")
				for e,x in pairs(game.Players:GetPlayers()) do
					print("Ran the Testing")
					print(x)
					if x == v then
						print("Gotcha")
				local RS = game:GetService("ReplicatedStorage")
				local Sword = RS.Sword:Clone()
				Sword.Parent = x.Backpack
									
					end
				end
			end
		end

I am using a table to express who is currently playing in the round, which is shown with the math.random(1,#Playing).

2 comments

0

oh god

0

uh ok

1 answer

Select a random player, then clone the tool into their backpack; something like this:

local Players = game:GetService("Players")

local NewRound = function()
	local Murderer = Players:GetPlayers()[math.random(1, #Players:GetPlayers())]
	local Sword = tool_here:Clone()
	Sword.Parent = Murderer.Backpack
	
	print(Murderer.Name .. " is the murderer")
end

NewRound()

1 comment

0

Well the reason why I create a table of the current players as "Playing" is because then I could remove and add people to the table. With just getting the players, I can't think of a way to separate the murderer from the detective, and so there might be a case where the murderer is also the detective?

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