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

How do I make this random elevator floor script work?

Asked by 4 years ago

So im trying to make a game like the normal elevator but i cant get my script to work

local floor = math.random(1,2)
local maps = game.ServerStorage.FLOORS

while true do
    if floor == 1 then
        maps.shronk:Clone(workspace) 
        wait(30)
        game.Workspace.shronk:Destroy() 
elseif floor == 2 then
        maps.tightrope:Clone(workspace)
        wait(30)
        game.Workspace.tightrope:Destroy()
    end
end

I dont understand why it wont work

0
it doesnt add the stuff into the game pokemon9master29 6 — 4y

1 answer

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

You aren't actually parenting the cloned object to anywhere so you must do this. You must also define a variable to tell the game what you want parented.

math.randomseed(tick())
local maps = game.ServerStorage.FLOORS

while true do
 local floor = math.random(1,2)
    if floor == 1 then
       ok =  maps.shronk:Clone()
        ok.Parent = game.Workspace
        wait(30)
        game.Workspace.shronk:Destroy() 
elseif floor == 2 then
       ok =  maps.tightrope:Clone()
        ok.Parent = game.Workspace
        wait(30)
        game.Workspace.tightrope:Destroy()
    end
end

I hope this helps, and good luck on your game!

0
Also make sure to put the "floor" variable inside the while true do. If you don't i think you will get the same number each time. ThatDevTim 188 — 4y
0
Yeah, you should put it in the while true do loop, and outside of the loop put math.randomseed(tick()) DarkDanny04 407 — 4y
Ad

Answer this question