Roblox Lua | How do i make a random number for EACH player?
Asked by
4 years ago Edited 4 years 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:
02 | local intermissionLength = 5 |
03 | local status = game.ReplicatedStorage.IntermissionStatus |
04 | local inround = game.ReplicatedStorage.InRound |
05 | local chosenRandomNumberValue = game.ReplicatedStorage.chosenNumber |
06 | local displaychosenrole = game.StarterGui.areyoumurdorsherifforinno.Chosen.TextLabel |
07 | local player = game.Players.LocalPlayer |
08 | local chosenRoleValue = game.ReplicatedStorage.TheChosenRole |
10 | local randomMapNumber = math.random( 1 , 3 ) |
13 | local mineshaft = game.Workspace.MineshaftSpawn |
14 | local milbase = game.Workspace.MilbaseSpawn |
15 | local lobby = game.Workspace.LobbySpawn |
16 | local ravenRock = game.Workspace.ravenrockSpawn |
18 | local function roundTimer() |
21 | for i = intermissionLength, 1 , - 1 do |
24 | status.Value = "Intermission: " .. i .. " seconds left!" |
28 | for i = roundLength, 1 , - 1 do |
31 | status.Value = "Game: " .. i .. " seconds left!" |
39 | inround.Changed:Connect( function () |
40 | if inround.Value = = true then |
42 | for _, player in pairs (game.Players:GetChildren()) do |
43 | local randomNumber = math.random( 1 , 3 ) |
44 | local char = player.Character |
45 | if randomMapNumber = = 1 then |
47 | char.HumanoidRootPart.CFrame = mineshaft.CFrame |
48 | elseif randomMapNumber = = 2 then |
49 | char.HumanoidRootPart.CFrame = milbase.CFrame |
50 | elseif randomMapNumber = = 3 then |
51 | char.HumanoidRootPart.CFrame = ravenRock.CFrame |
55 | if randomNumber = = 1 then |
56 | player.TeamColor = BrickColor.new( "Institutional white" ) |
57 | chosenRoleValue.Value = "MURDERER" |
58 | elseif randomNumber = = 2 then |
59 | player.TeamColor = BrickColor.new( "Institutional white" ) |
60 | chosenRoleValue.Value = "SHERIFF" |
61 | elseif randomNumber = = 3 then |
62 | player.TeamColor = BrickColor.new( "Institutional white" ) |
63 | chosenRoleValue.Value = "INNOCENT" |
68 | for _,player in pairs (game.Players:GetChildren()) do |
69 | local char = player.Character |
70 | char.HumanoidRootPart.CFrame = lobby.CFrame |
71 | player.TeamColor = BrickColor.new( "Medium stone grey" ) |
72 | chosenRoleValue.Value = "NEUTRAL" |
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.