Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What does this error mean?

Asked by 9 years ago

I have no idea what this error means.

21:27:06.767 - Players.Player1.PlayerGui.LocalScript:5: bad argument #2 to 'random' (interval is empty) 21:27:06.771 - Script 'Players.Player1.PlayerGui.LocalScript', Line 5 21:27:06.774 - Stack End Script:

faces = {face1 = "http://www.roblox.com/asset/?id=162384466",face2 = "http://www.roblox.com/asset/?id=162387197",face3 = "http://www.roblox.com/asset/?id=162387541"}
h = script.Parent.Parent.Character.Head
player = game.Players.LocalPlayer
hft = h.face.Texture
rm = math.random(1,#faces)
hft = rm

I have all the asset ids right cause i -1 them all so I don't know whats going on now. Please help! Thanks!

0
Somehow, '#faces' is returning less than 1. BTW, you don't need the 1 in the math.random. GoldenPhysics 474 — 9y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

interval is empty means that the second parameter to math.random is less than the first, e.g.,

math.random(10,3);

will trigger this error.



The reason you are getting this error is because #faces is 0 (you can check this yourself by printing it) which is less than 1, your first parameter to math.random.

This is because # (table length) only includes elements with the keys 1, 2, 3, ...; however, you are using "face1", "face2", ....

It only counts those elements, because, for instance, if we computed the length to be 3 and chose randomly the index 2, well, faces[2] is nil, because 2 is not "face2".

You just need a list, so your definition of faces should be more like this:

faces = {
    "http://www.roblox.com/asset/?id=162384466",
    "http://www.roblox.com/asset/?id=162387197",
    "http://www.roblox.com/asset/?id=162387541"
}


While I don't know exactly what you're doing, I'm guessing your line 06 should be:

hft = faces[rm]

This would set hft to a texture (from faces) as opposed to a number 1 to 3.

Ad

Answer this question