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

What did I do wrong in this stage randomizer script?

Asked by 3 years ago

Hey everyone, so I wrote this script for a stage randomizer, but when it chooses stage 5 it stays stuck and doesn't change after a minute anymore, does anyone know/see why this happens? (i added a few more if pickedmap ~= nil then because it was doing an error, my problem is not because of this, because it also didnt change away from stage 5 before i added the if ~= nil then) The script:

while true do
    local pickedmap = math.random(1,5)
    print(pickedmap)
    wait(2)
    print(pickedmap)
    if pickedmap ~= nil then
        pickedmap = math.random(1,5)
        print(pickedmap)
    end
    if pickedmap == 1 then
        if pickedmap ~= nil then
            pickedmap = math.random(1,5)
            print(pickedmap)
        end
        workspace.Dodge.parts.Transparency = 0
        workspace.Dodge.parts.CanCollide = true
        workspace.Dodge.killparts.Transparency = 0
        workspace.Dodge.killparts.Script.Disabled = false

        wait(60)

        workspace.Dodge.parts.Transparency = 1
        workspace.Dodge.parts.CanCollide = false
        workspace.Dodge.killparts.Transparency = 1
        workspace.Dodge.killparts.Script.Disabled = true
    end
    if pickedmap == 2 then
        if pickedmap ~= nil then
            pickedmap = math.random(1,5)
            print(pickedmap)
        end
        workspace.Topjump.conveyors.a.Transparency = 0
        workspace.Topjump.conveyors.b.Transparency = 0
        workspace.Topjump.conveyors.a.CanCollide = true
        workspace.Topjump.conveyors.b.CanCollide = true
        workspace.Topjump.part.CanCollide = true
        workspace.Topjump.part.Transparency = 0.3
        workspace.Topjump.killparts.Script.Disabled = false
        workspace.Topjump.killparts.Transparency = 0

        wait(60)

        workspace.Topjump.conveyors.a.Transparency = 1
        workspace.Topjump.conveyors.b.Transparency = 1
        workspace.Topjump.conveyors.a.CanCollide = false
        workspace.Topjump.conveyors.b.CanCollide = false
        workspace.Topjump.part.CanCollide = false
        workspace.Topjump.part.Transparency = 1
        workspace.Topjump.killparts.Script.Disabled = true
        workspace.Topjump.killparts.Transparency = 1
    end
    if pickedmap == 3 then
        if pickedmap ~= nil then
            pickedmap = math.random(1,5)
            print(pickedmap)
        end
        workspace.Pushingaway.conveyors.a.Transparency = 0
        workspace.Pushingaway.conveyors.b.Transparency = 0
        workspace.Pushingaway.conveyors.c.Transparency = 0
        workspace.Pushingaway.conveyors.d.Transparency = 0
        workspace.Pushingaway.conveyors.e.Transparency = 0
        workspace.Pushingaway.conveyors.f.Transparency = 0
        workspace.Pushingaway.conveyors.g.Transparency = 0
        workspace.Pushingaway.conveyors.h.Transparency = 0
        workspace.Pushingaway.conveyors.a.CanCollide = true
        workspace.Pushingaway.conveyors.b.CanCollide = true
        workspace.Pushingaway.conveyors.c.CanCollide = true
        workspace.Pushingaway.conveyors.d.CanCollide = true
        workspace.Pushingaway.conveyors.e.CanCollide = true
        workspace.Pushingaway.conveyors.f.CanCollide = true
        workspace.Pushingaway.conveyors.g.CanCollide = true
        workspace.Pushingaway.conveyors.h.CanCollide = true
        workspace.Pushingaway.part.CanCollide = true
        workspace.Pushingaway.part.Transparency = 0
        workspace.Pushingaway.killparts.Script.Disabled = false
        workspace.Pushingaway.killparts.Transparency = 0

        wait(60)

        workspace.Pushingaway.conveyors.a.Transparency = 1
        workspace.Pushingaway.conveyors.b.Transparency = 1
        workspace.Pushingaway.conveyors.c.Transparency = 1
        workspace.Pushingaway.conveyors.d.Transparency = 1
        workspace.Pushingaway.conveyors.e.Transparency = 1
        workspace.Pushingaway.conveyors.f.Transparency = 1
        workspace.Pushingaway.conveyors.g.Transparency = 1
        workspace.Pushingaway.conveyors.h.Transparency = 1
        workspace.Pushingaway.conveyors.a.CanCollide = false
        workspace.Pushingaway.conveyors.b.CanCollide = false
        workspace.Pushingaway.conveyors.c.CanCollide = false
        workspace.Pushingaway.conveyors.d.CanCollide = false
        workspace.Pushingaway.conveyors.e.CanCollide = false
        workspace.Pushingaway.conveyors.f.CanCollide = false
        workspace.Pushingaway.conveyors.g.CanCollide = false
        workspace.Pushingaway.conveyors.h.CanCollide = false
        workspace.Pushingaway.part.CanCollide = false
        workspace.Pushingaway.part.Transparency = 1
        workspace.Pushingaway.killparts.Script.Disabled = true
        workspace.Pushingaway.killparts.Transparency = 1
    end 
    if pickedmap == 4 then
        if pickedmap ~= nil then
            pickedmap = math.random(1,5)
            print(pickedmap)
        end
        workspace.Workingback.Conveyors.a.Transparency = 0
        workspace.Workingback.Conveyors.b.Transparency = 0
        workspace.Workingback.Conveyors.c.Transparency = 0
        workspace.Workingback.Conveyors.d.Transparency = 0
        workspace.Workingback.Conveyors.e.Transparency = 0
        workspace.Workingback.Conveyors.f.Transparency = 0
        workspace.Workingback.Conveyors.g.Transparency = 0
        workspace.Workingback.Conveyors.a.CanCollide = true
        workspace.Workingback.Conveyors.b.CanCollide = true
        workspace.Workingback.Conveyors.c.CanCollide = true
        workspace.Workingback.Conveyors.d.CanCollide = true
        workspace.Workingback.Conveyors.e.CanCollide = true
        workspace.Workingback.Conveyors.f.CanCollide = true
        workspace.Workingback.Conveyors.g.CanCollide = true
        workspace.Workingback.killparts.Script.Disabled = false
        workspace.Workingback.killparts.Transparency = 0
        workspace.Workingback.parts.Transparency = 0
        workspace.Workingback.parts.CanCollide = true

        wait(60)

        workspace.Workingback.Conveyors.a.Transparency = 1
        workspace.Workingback.Conveyors.b.Transparency = 1
        workspace.Workingback.Conveyors.c.Transparency = 1
        workspace.Workingback.Conveyors.d.Transparency = 1
        workspace.Workingback.Conveyors.e.Transparency = 1
        workspace.Workingback.Conveyors.f.Transparency = 1
        workspace.Workingback.Conveyors.g.Transparency = 1
        workspace.Workingback.Conveyors.a.CanCollide = false
        workspace.Workingback.Conveyors.b.CanCollide = false
        workspace.Workingback.Conveyors.c.CanCollide = false
        workspace.Workingback.Conveyors.d.CanCollide = false
        workspace.Workingback.Conveyors.e.CanCollide = false
        workspace.Workingback.Conveyors.f.CanCollide = false
        workspace.Workingback.Conveyors.g.CanCollide = false
        workspace.Workingback.killparts.Script.Disabled = true
        workspace.Workingback.killparts.Transparency = 1
        workspace.Workingback.parts.Transparency = 1
        workspace.Workingback.parts.CanCollide = false
    end
    if pickedmap == 5 then
        if pickedmap ~= nil then
            pickedmap = math.random(1,5)
            print(pickedmap)
        end
        workspace.Speedpush.conveyors.a.Transparency = 0
        workspace.Speedpush.conveyors.b.Transparency = 0
        workspace.Speedpush.conveyors.c.Transparency = 0
        workspace.Speedpush.conveyors.d.Transparency = 0
        workspace.Speedpush.conveyors.e.Transparency = 0
        workspace.Speedpush.conveyors.a.CanCollide = true
        workspace.Speedpush.conveyors.b.CanCollide = true
        workspace.Speedpush.conveyors.c.CanCollide = true
        workspace.Speedpush.conveyors.d.CanCollide = true
        workspace.Speedpush.conveyors.e.CanCollide = true
        workspace.Speedpush.Part.Transparency = 0
        workspace.Speedpush.Part.CanCollide = true
        workspace.Speedpush.killparts.Script.Disabled = false
        workspace.Speedpush.killparts.Transparency = 0

        wait(60)

        workspace.Speedpush.conveyors.a.Transparency = 1
        workspace.Speedpush.conveyors.b.Transparency = 1
        workspace.Speedpush.conveyors.c.Transparency = 1
        workspace.Speedpush.conveyors.d.Transparency = 1
        workspace.Speedpush.conveyors.e.Transparency = 1
        workspace.Speedpush.conveyors.a.CanCollide = false
        workspace.Speedpush.conveyors.b.CanCollide = false
        workspace.Speedpush.conveyors.c.CanCollide = false
        workspace.Speedpush.conveyors.d.CanCollide = false
        workspace.Speedpush.conveyors.e.CanCollide = false
        workspace.Speedpush.Part.Transparency = 1
        workspace.Speedpush.Part.CanCollide = false
        workspace.Speedpush.killparts.Script.Disabled = true
        workspace.Speedpush.killparts.Transparency = 1
    end
    if pickedmap ~= nil then
        pickedmap = math.random(1,5)
        print(pickedmap)
    end

end

2 answers

Log in to vote
1
Answered by 3 years ago

I'm not even going to bother trying to scan through all those lines for an error lol. However, I'll write up a basic code for you that you can use as a template:

--// Services:
local _RS = game:GetService("ReplicatedStorage");

--// References:
local maps = _RS:WaitForChild("Maps"):GetChildren();

--// Variables:
local roundDuration = 10 -- Time (in seconds) that rounds take. 10 IS VERY SHORT!
local intermission = 15 -- Break (in seconds) between rounds

--// Cached Functions:
local random = math.random;

--// Core:
while true do

    local pickedMap = maps[random(1,#maps)]:clone()

    wait(intermission);

    pickedMap.Parent = game.Workspace;

    if pickedMap.Name == "Whatever Map Name" then
        --Do stuff according to the specific map
    elseif pickedMap.Name == "Whatever Map Name" then
        --Do stuff according to the specific map
    end

    wait(roundDuration);

    --Teleport players back to lobby or whatever

    pickedMap:Destroy();

end
0
Hopefully this helps you out a little bit! isaacsoccer 45 — 3y
0
Im kind of new to scripting so I don't really understand what this is exactly for, is this a script to put the stage from replicatedstorage into workspace? sinbadxfan05 3 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

ok you should do something like this if u cant understand i can say what this do

DONT FORGET TO PUT IT ON A SCRIPT

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Maps = ReplicatedStorage.Maps:GetChildren()
local Parent = workspace -- this is the parent of map when map choose

local InGameMap -- dont change or remove this

math.randomseed(tick())

while true do
    if InGameMap then
        InGameMap:Destroy()
    end

    local RandomNumber = math.random(1, #Maps) -- this is choose a random map between 5 map and #Maps get the maps we have like 5 - 6 - 7 - 10

    local Map = Maps[RandomNumber] -- this line choose the Map it get the map

    InGameMap = Map:Clone() -- this line clone the choosed map
    InGameMap.Parent = Parent -- this line put the cloned map on workspace u can put it on everywhere u want. Only choose the Parent Variable

    wait(20) -- this is how much a round take u can change it
end

Answer this question