[SOLVED] Another problem about 'random' (interval is empty)

I got an error that said:
Workspace.Trigger.Script:19: invalid argument #1 to ‘random’ (interval is empty) - Server - Script:19

I don’t know what to do at all. I checked other posts but they seem to have a different solution. What should I do in this case?

Code:

local Players = game:GetService('Players')
local ServerStorage = game:GetService('ServerStorage')

local Trigger = script.Parent
local Obby = Trigger.Parent

Trigger.Touched:Connect(function(part)
	-- Check if the player touches it
	local character = part.Parent
	local player = Players:GetPlayerFromCharacter(character)
	if not player then return end
	
	-- Disable trigger
	script.Enabled = false
	
	-- Create a new obby
	local ObbyStructure = ServerStorage:WaitForChild('ObbyStructure')
	local Obbies = ObbyStructure:GetChildren()
	local ChosenObby = Obbies[math.random(#Obbies)] -- Heres the problem
	
	local ObbyCount = ServerStorage.Values:FindFirstChild('ObbyCount')
	ObbyCount.Value += 1
	
	local PreviousObby = workspace:FindFirstChild('Obby'..(ObbyCount.Value - 1)) or nil
	local Finish = nil
	if PreviousObby then Finish = PreviousObby:FindFirstChild('Finish') end
	
	ChosenObby.Parent = workspace
	ChosenObby.Name = 'Obby'..ObbyCount.Value
	ChosenObby:PivotTo((Finish or workspace.StartSpawn.Finish).CFrame)
	
	-- Obby to be destroyed
	local ExistingObbies = ServerStorage.Values:FindFirstChild('ExistingObbies')
	local ObbyTBD = workspace:FindFirstChild('Obby'..(ObbyCount.Value - ExistingObbies.Value))
	if ObbyTBD then ObbyTBD:Destroy() end
	
	-- Move and enable trigger
	Trigger.Position = ChosenObby.Checkpoints.Checkpoint.Position + Vector3.new(0, 4.5, 0)
	script.Enabled = true
end)

My goal here is to make an infinitely generating obby, that is. There are 6 models in the ‘ObbyStructure’ folder but somehow it doesnt even know how many

I tried to set math.random to 6 but it doesnt even get an item from the object

That would mean there is nothing in it, as if you only apply a maximum value, the default minimum is 1, so the code would be seeing that the mimimum is 1, but the maximum is 0.

1 Like

‘Obbies’ is empty. The problem lays in fetching ObbyStructure. Put a temporary obby in workspace and try it on that, see if it works.

Have you tried doing
local ChosenObby = Obbies[math.random(1, #Obbies)]
instead?

it gave the #2 argument, i dont know why

eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

theres like 6 models inside the folder, but it perceives it as 0?

ill probably try and put obbystructure in replicatedstorage, as serverstorage is a bit, unpredictable to say the least. but it still fetched obbystructure though because of the waitforchild() thing. but i dont know why it cant fetch anything inside it

For context: The sets of obbies (6) were suddenly deleted for some reason. Why though? I don’t know. Is it my scripts? No, I checked all my scripts they’re free of viruses or something. I checked both the Client and Server and they’re not rendering anything inside of ObbyStructure.

Update: My mistake, I forgot ‘clone’. Shutting down this post

1 Like

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