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

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

Asked by 4 years ago
Edited 3 years ago

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.

0
What do you mean "in a row"? Raccoonyz 1092 — 4y
0
I mean I keep getting the same map over and over again DecalMaker2468 21 — 4y
0
just use math.random(1,4) VVoretex 146 — 4y
0
hmm okay. DecalMaker2468 21 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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
THANKS! DecalMaker2468 21 — 4y
Ad

Answer this question