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

Murder Mystery script sometimes letting the wrong side win. How would i fix it?

Asked by 1 year ago

So basically I made a Murder Mystery script but sometimes the wrong side wins. Example: The murderer dies but then the murderer wins. Another example: The murderer kills everyone but then the murderer loses

I ofc can’t find anything on the devforum cause yk. Also I tried on my own.

heres my script:

local murdersystem = {}
function murdersystem.ChooseRoles()
    local players = game:GetService("Players")
    local playersingame = {}
    local Teams = game:GetService("Teams") 

    local teamPlayers = Teams["Playing"]:GetPlayers()
    for i, p in pairs(players:GetChildren()) do
        table.insert(playersingame, p.Name)
    end

    if #playersingame >= 1 then

        local murderer = playersingame[math.random(1, #playersingame)]
        table.remove(playersingame, table.find(playersingame, murderer))
        players:FindFirstChild(murderer):WaitForChild("Role").Value = "Murderer"

        local sherrif = playersingame[math.random(1, #playersingame)]
        table.remove(playersingame, table.find(playersingame, sherrif))
        players:FindFirstChild(sherrif):WaitForChild("Role").Value = "Detective"



        for i, plrname in pairs(playersingame) do
            players:FindFirstChild(plrname):WaitForChild("Role").Value = "Witness"

        end



        wait(5)
        for i, playerInRound in pairs(players:GetChildren()) do
            if playerInRound.Team.Name == "Playing" then
                game.ReplicatedStorage.DisplayRole:FireClient(playerInRound)
            end
        end
        wait(5)
        local knifeclone = game.ReplicatedStorage.Knife:Clone()
        if players:FindFirstChild(murderer) then
            knifeclone.Parent = players:FindFirstChild(murderer).Backpack
            print("gave knife to ".. murderer)
        end


        local gunclone = game.ReplicatedStorage.Gun:Clone()
        if players:FindFirstChild(sherrif) then
            gunclone.Parent = players:FindFirstChild(sherrif).Backpack
            print("gave gun to ".. sherrif)
        end



        return murderer
    else

        return "Not Enough Players"
    end
end
return murdersystem

0
Where in your script are you detecting who wins? would you be able to add a comment? I am not sure what you are trying to do. bittyboy1234 91 — 1y

Answer this question