Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Roblox Lua | How do i make a random number for EACH player?

Asked by 8 days ago
Edited 7 days ago

So, im trying to make an system to choose an role for each player, and also choose a map for all players, so i tried this:

local roundLength = 10
local intermissionLength = 5
local status = game.ReplicatedStorage.IntermissionStatus
local inround = game.ReplicatedStorage.InRound
local chosenRandomNumberValue = game.ReplicatedStorage.chosenNumber
local displaychosenrole = game.StarterGui.areyoumurdorsherifforinno.Chosen.TextLabel
local player = game.Players.LocalPlayer
local chosenRoleValue = game.ReplicatedStorage.TheChosenRole

local randomMapNumber = math.random(1,3)


local mineshaft = game.Workspace.MineshaftSpawn
local milbase = game.Workspace.MilbaseSpawn
local lobby = game.Workspace.LobbySpawn
local ravenRock = game.Workspace.ravenrockSpawn

local function roundTimer()

    while wait() do
        for i = intermissionLength, 1, -1 do
            inround.Value = false
            wait(1)
            status.Value = "Intermission: ".. i .." seconds left!"
            wait(1)

        end
        for i = roundLength, 1, -1 do
            inround.Value = true
            wait(1)
            status.Value = "Game: ".. i .." seconds left!"

        end

    end

end

inround.Changed:Connect(function()
    if inround.Value == true then   

        for _, player in pairs(game.Players:GetChildren()) do
            local randomNumber = math.random(1,3)
            local char = player.Character
            if randomMapNumber == 1 then

                char.HumanoidRootPart.CFrame = mineshaft.CFrame
            elseif randomMapNumber == 2 then
                char.HumanoidRootPart.CFrame = milbase.CFrame
            elseif randomMapNumber == 3 then
                char.HumanoidRootPart.CFrame = ravenRock.CFrame
            end


            if randomNumber == 1 then
                player.TeamColor = BrickColor.new("Institutional white")    
                chosenRoleValue.Value = "MURDERER"
            elseif randomNumber == 2 then
                player.TeamColor = BrickColor.new("Institutional white")
                chosenRoleValue.Value = "SHERIFF"
            elseif randomNumber == 3 then
                player.TeamColor = BrickColor.new("Institutional white")
                chosenRoleValue.Value = "INNOCENT"
            end

        end
    else
        for _,player in pairs(game.Players:GetChildren()) do
            local char = player.Character
            char.HumanoidRootPart.CFrame = lobby.CFrame     
            player.TeamColor = BrickColor.new("Medium stone grey")
            chosenRoleValue.Value = "NEUTRAL"

        end
    end

end)


spawn(roundTimer)   

And of course, it chooses an map for each player, and every player has the same role.. I tried switching it, and even doing it in another script, also i this is in "ServerScriptService", ofc its a normal script. Also does it need to be a local script, because if it does then how do i do that then, because i cant put a local script in "ServerScriptStorage". Also i want to make it so that only 1 player gets murderer, and only one sheriff, all the others become innocents.

1
You can store the different roles in a table, then let it randomly choose one of the roles u put in the table, and when a certain role is taken you remove it from the table. DeUltimate23 59 — 8d
0
I mean this is just another way to do it, DeUltimate23 59 — 8d
0
why are you settings everyones team color to the same color testing34545 9 — 8d
0
@testing34545 because i have 2 teams, playing and waiting, so that in the chat the murderer isnt red, and so on. VikkiVuk 39 — 8d
0
so how do i make it that only murderer and sheriff get removed, and everyone else becomes innocent? please post this as an answer, also i have no clue how to do the tables.. VikkiVuk 39 — 8d

Answer this question