Script always breaks after 20 minutes

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to figure out why this script suddenly stops working after playing for about 20 minutes

  2. What is the issue? Include screenshots / videos if possible!
    I wanted to make a “crazy elevator” styled game but its set in space,…I watched some yt tutorial and got a script from the toolbox, not always reliable but i modified it and it works perfectly!, the timer works, the randomizer for the maps (floors) work and im not getting any errors, the only problem is (like i said in the title) that after playing for about 20 minutes the entire script suddenly stops functioning and i get this error: " ServerScriptService.Elevator Script:85: attempt to index nil with ‘Clone’ "

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I haven’t found anything like this on the dev forum yet so I tried making a script that refreshes the main script every few seconds by cloning it , deleting the original one and setting the clone’s parent to the original script’s parent. It obviously didn’t work and gave the same results.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

This is the script located in serverscriptservice with the name :“elevator script”

-- -- Ajedi32 created the script!
-- Vitorrobloxgames edited Script and instructions!
local Particles = game.Workspace.Particles
local Thruster  = game.Workspace.MemeSpaceShip1000.Thruster
disasters = {"Noobception","AstralShrek","WorldTripWithAdrien","AstroidsAndTacos","OCEANMAN","CHEEMSvsPIGEON","BANANAS","Uhhh","OneThousandBobux","Banland","SwordFightsOnTheHeights","WOOOOOOOHH","MixUp","Mario","SoftcoreParkour","WereCrashingAAAAH","SpaceRacing","DogOfWisdom","Lemon Demon >:)","AverageFan_VS_AverageEnjoyer","Uhhh_2"} -- This is where you list the names models that you want to use for FLOORS.
-- The list must look like this {"001","002",} and so on.
-- Floor names are case-sensitive and all Floor models must be in the lighting
local RandInstance =
local chosenmap = script:WaitForChild("ChosenMap")

countdownTime = 20 -- The ammount of time to wait between each Floor.
disasterTime = 60 -- The ammount of time that the Floor will be in the game before it is removed.

countdownMessage = "Next Stop in %s seconds!" -- The message displayed between disasters. %s will be replaced with the number of seconds left.
disasterMessage = "Floor: %s" -- The message displayed when a disaster occurs. %s will be replaced with the disaster name. Set to nil if you do not want a message

-- Unless you know what you are doing, please leave the below code alone.
items = {}
leaderboard = game.ServerScriptService:findFirstChild("datastore") -- Used to work with my BTS leaderboard
local w = game.ServerScriptService:getChildren()
for i=1,#w do
	if w[i].Name == "datastore" and w[i]:findFirstChild("running") ~= nil and w[i]:findFirstChild("points") ~= nil then
		leaderboard = w[i]
for i=1,#disasters do
	local item = game.ServerStorage.Maps:findFirstChild(disasters[i])
	if item ~= nil then
		item.Parent = nil
		table.insert(items, item)
		print("Error! ", disasters[i], " was not found!")

function sethint(text)
	local hint = game.Workspace:findFirstChild("hint")
	if (hint ~= nil) then
		hint.Text = text
		print("Hint does not exist, creating...")
		hint ="Hint")
		hint.Name = "hint"
		hint.Text = text
		hint.Parent = game.Workspace
	--print("Hint set to: ", text)

function removeHint()
	hint = game.Workspace:findFirstChild("hint")
	if (hint ~= nil) then hint:remove() end

function countdown(time)
	sethint(string.format(countdownMessage, tostring(time)))
	while (time > 0) do
		time = time - 1
		sethint(string.format(countdownMessage, tostring(time)))
	return true

while true do

	if leaderboard ~= nil and leaderboard:findFirstChild("running") and leaderboard:findFirstChild("points") then -- For use with my BTS leaderboard.
		leaderboard.points.Value = 30 --Points after you survive disasters.
		leaderboard.running.Value = true
	function chooseDisaster()
		return items[RandInstance:NextInteger(0, #items)]
	local m = chooseDisaster():Clone()  -----**This is the part that errors after 20 minutes**

	if disasterMessage ~= nil then
		local msg ="Message")
		msg.Name = "DisasterMsg"
		msg.Text = string.format(disasterMessage, m.Name)
		msg.Parent = game.Workspace
		msg.Parent = nil
	m.Parent = game.Workspace.currentmap
	game.Workspace.FakeDoor.Transparency = 1
	game.Workspace.FakeDoor.CanCollide = false = false = false = false
	Particles.df.ParticleEmitter.Enabled = false = false
	Particles.hj.ParticleEmitter.Enabled = false = false = false = false
	print("m added")
	game.Workspace.FakeDoor.Transparency = 0.4
	game.Workspace.FakeDoor.CanCollide = true = true = true = true
	Particles.df.ParticleEmitter.Enabled = true = true
	Particles.hj.ParticleEmitter.Enabled = true = true = true = true
	local Players = game:GetService('Players')

	local Targets = Players:GetPlayers() -- Assigning it as a local is faster.
	for _, Player in ipairs(Targets) do
		local LowerTorso = Player.Character.LowerTorso
		LowerTorso.CFrame =
		if Player.Character.LowerTorso == nil then
			local Torso = Player.Character.Torso
			Torso.CFrame =
		game.StarterPlayer.CharacterWalkSpeed = 16
	print("m removed")

	if leaderboard ~= nil then -- For use with the bts leaderboard.
		leaderboard.running.Value = false

chooseDisaster(disasters, RandInstance:NextInteger(0, #disasters))

Here’s some screenshots of the locations of the script and the folder where the current map is placed in.
Elevator Script - Roblox Studio 6_04_2021 10_55_31 (2) Elevator Script - Roblox Studio 6_04_2021 10_56_19 (2)

I think it may be related to this, as there’s no real 0 index in Luau, so it has to be from 1 to the length of the items table, it’s probably erroring as it randomly gets 0 and it doesn’t find anything with na index of 0 in the table and gets nil, try this

return items[RandInstance:NextInteger(1, #items)]

And see if the erroring stops

1 Like