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

How do I make this random elevator floor script work?

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

1 comment

0

it doesnt add the stuff into the game

1 answer

✓ Accepted answer

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!

2 comments

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.

0

Yeah, you should put it in the while true do loop, and outside of the loop put math.randomseed(tick())

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