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).
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()