Table Randomizer Error: invalid argument #2 to ‘random’ (interval is empty)

To put it simply, I want to randomize a decal when it is not shown. I have an external script which shows the decal when needed. But with the script I have which randomizes the decal itself, I am getting an error. The error is as follows:

“Players.GodzillaGamer1954.PlayerGui.StatusUI.BloodSplatter.LocalScript:14: invalid argument #2 to ‘random’ (interval is empty)”

Here’s the script the error is referring to:

Script
--Variables
local blood = script.Parent

--Tables
local splatters = {
	splatter1 = {ID = 409191497, Size = {1.05, 0},{1.5, 0}},
	splatter2 = {ID = 400462004, Size = {1.05, 0},{1.75, 0}},
	splatter3 = {ID = 246162648, Size = {1.05, 0},{1.5, 0}}
}

--Loops
while true do
	if blood.ImageTransparency == 1 then
		local value = math.random(1,#splatters)
		local picked_value = splatters[value]
		blood.Image = picked_value.ID
		blood.Size = picked_value.Size
	end
	wait()
end

I am also unsure if the actual image link and size will change when it says so.

How would I make this script work?

Try use #splatters:GetChildren()

3 Likes

Alright, I’ll try doing that to see if it works.

The dictionary part of a table does not count towards the length of the table.

Since all that matters here is the order you can just make it an array:

local splatters = {
	{ID = 409191497, Size = UDim2.new(1.05, 0, 1.5, 0)},
	{ID = 400462004, Size = UDim2.new(1.05, 0, 1.75, 0)},
	{ID = 246162648, Size = UDim2.new(1.05, 0, 1.5, 0)}
}

Also size should be a UDim2, not a table

1 Like

I added the rbxasset thing in front of the ID and it worked! Thanks for your help.