Invalid argument #2 to 'random' (interval is empty)

i want to randomly choose a position but i dont know why it failed leaving this error message

Lua
game.ServerScriptService.VentSpawn.SpawnVent.Event:Connect(function()
local Spawns = game.Workspace.Ventpos:GetChildren()
local randomSpawn = Spawns[math.random(1,#Spawns)]

workspace.Vent:SetPrimaryPartCFrame(CFrame.new(randomSpawn.Position))

end)

According to error, length of spawns table is smaller than 1 so there is nothing in Spawns table.

but there is position in the table and its more than 1

Can you put print(#Spawns) between the 2nd and 3rd line so we can see how many objects are in that table?

Could you maybe send an image of the explorer tab we are looking at? Could make this a lot easier.

You’re putting a .Position into a CFrame, a CFrame is a CFrame, and a position is a Vector3, you can’t mix those.

You can put a Vector3 value as an argument in a CFrame.new() constructor.
image

You can, but you would need to put in 2 vector3’s, as a CFrame holds 6 values unlike a Vector3, (in the case of the person who posted this)

You don’t need to put 2 Vector3 values in a CFrame.new() constructor, the 2nd Vector3 value just exists as a lookat vector to and not necessary when creating a CFrame value.

Clearly it wants a 2nd argument.

hehe

i printed #Spawn but its 0 i dont why in the folder theres positions

fafafa

It doesn’t want a 2nd argument, the problem here is not the CFrame here, the problem here is that :GetChildren() is not returning anything.

its not complaining about the cframe, send a screenshot of the script, it says error on line 4 which was on line 3 before

Maybe script runs before Ventpos starts loading it’s contents?

no thats not it in the fire() script theres a wait

Spawns[math.random(#Spawns)]

Don’t name the parts Position, it would be confusing whenever you try to read it, mixing up with BasePart.Position.

yeah ok but can you tell what is wrong with the code?

Actually, were those parts in place constantly or were they loaded by some code for loading? That would explain it as there might have been an error in timing.

those part was place constantly

The other possibility is that something else is named Ventpos which is empty.