Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This script doesn't send players to different towers? [NEW]

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.

4 comments

0

What do you mean "in a row"?

0

I mean I keep getting the same map over and over again

0

just use math.random(1,4)

0

hmm okay.

1 answer

✓ Accepted answer

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!

1 comment

1

THANKS!

This discussion is preserved as it was. New answers, comments, and votes are closed.