This script sends the players from lobby to the game and to the lobby back and it has a randomizer that is supposed to randomize what kind of tower I will play in, but when I run it I always go to a map in a row and it doesn't change.
local TowerGenerator = math.random(1,2) local LobbySpawn = game.Workspace.Lobby.Floor.Center.SpawnLocation local Normal = game.Workspace.Normal.Ground.Teleporter local MoltenCave = game.Workspace.Molten_Cave.Ground.Teleporter inRound.Changed:Connect(function() if inRound.Value == true then for _, player in pairs(game.Players:GetChildren())do local char = player.Character if TowerGenerator == 1 then char.HumanoidRootPart.CFrame = Normal.CFrame else char.HumanoidRootPart.CFrame = MoltenCave.CFrame end end else for _, player in pairs(game.Players:GetChildren())do local char = player.Character char.HumanoidRootPart.CFrame = LobbySpawn.CFrame end end end)
P.S: This is just a portion of the script, plus my original question is not getting attention.
The problem is that TowerGenerator only gets a random value when it is first initialized, it stays the same until the script runs again. This is why you keep getting the same results in a row.
Here's your script but with the change:
local TowerGenerator = math.random(1,2) local LobbySpawn = game.Workspace.Lobby.Floor.Center.SpawnLocation local Normal = game.Workspace.Normal.Ground.Teleporter local MoltenCave = game.Workspace.Molten_Cave.Ground.Teleporter inRound.Changed:Connect(function() if inRound.Value == true then TowerGenerator = math.random(1,2) -- New line of code randomizes value for _, player in pairs(game.Players:GetChildren())do local char = player.Character if TowerGenerator == 1 then char.HumanoidRootPart.CFrame = Normal.CFrame else char.HumanoidRootPart.CFrame = MoltenCave.CFrame end end else for _, player in pairs(game.Players:GetChildren())do local char = player.Character char.HumanoidRootPart.CFrame = LobbySpawn.CFrame end end end)
Have a good day!