#repeat until not working right

3 messages · Page 1 of 1 (latest)

dense fulcrum
#

im making an elevator game and i have each floor stored in a table. im trying to make it so it wont spawn the same floor twice in a row. this is what i currently have.

    game.ReplicatedStorage.Floors.TestFloor1,
    game.ReplicatedStorage.Floors.TestFloor2,
    game.ReplicatedStorage.Floors.TestFloor3
}

local chosenFloor
local previousFloor = -1

while true do
    repeat
        chosenFloor = floors[math.random(#floors)]
    until chosenFloor ~= previousFloor
    
    previousFloor = chosenFloor
    
    chosenFloor:Clone()
    chosenFloor.Parent = workspace
    chosenFloor:PivotTo(workspace.Elevator.FloorSpawn.CFrame)
    
    task.wait(1)
    chosenFloor:Destroy()
end

if you need me to elaborate more i can. im relatively new to roblox scripting, so dont be harsh

#

what it does right now is it spawns the floors just fine, but when its a duplicate instead of running the loop, it just destroys the model and stops the script

scarlet crest
# dense fulcrum im making an elevator game and i have each floor stored in a table. im trying to...
local floors = {
    game.ReplicatedStorage.Floors.TestFloor1,
    game.ReplicatedStorage.Floors.TestFloor2,
    game.ReplicatedStorage.Floors.TestFloor3
}

local chosenFloor
local previousFloor = -1

while true do
    repeat
        chosenFloor = floors[math.random(#floors)]
    until chosenFloor ~= previousFloor
    
    previousFloor = chosenFloor
    
    local newFloor = chosenFloor:Clone()
    newFloor.Parent = workspace
    newFloor:PivotTo(workspace.Elevator.FloorSpawn.CFrame)
    
    task.wait(1)
end```