Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

0
oh god User#6546 35 — 4y
0
uh ok Mellodax 2 — 4y

1 answer

Log in to vote
0
Answered by
Upbolt 20
4 years ago

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()
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? Mellodax 2 — 4y
Ad

Answer this question