Weird error which I have no idea why its happening

So I have some round loop and in the round loop there is this code:

	local lobbyMusic = game.Workspace.lobbyMusic["rblxLobbyMusic"..math.random(1,7)]
	game.Workspace.soundEffects.ohioScream.SoundId = "rbxassetid://9399994950"
	lobbyMusic:Play()
	lobbyMusic.TimePosition = math.random(1,(lobbyMusic.TimeLength - 30))

however, the last line errors rarely, I have only encountered it once but I looked at my cached internal server errors in my servers and fount that the last line errors very rarely. This is the error:
“ServerScriptService.roundScript:927: invalid argument #2 to ‘random’ (interval is empty)”
I don’t know why sometimes this property time length property , because if the lobbyMusic instance does not exist, then the other code before it wont work.

You get this error because the max number is less than the min number, This is likely do to the sound taking time to load so you should probably preload it or Wait for it to not be 0.

1 Like

task.wait(2) should fix this … just before the play() line.

1 Like

Thanks for the help, but I have a round loop and it is essential to have everything run sequentially. I am just doing a repeat wait() loop until time length ~= 0.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.