Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Making a Character Creation??

So this is what my script is.

I keep getting this error that says Players.Player.PlayerGui.Menu.Frame.Hats.LocalScript:18: bad argument #1 to 'random' (interval is empty)

local hats = 
{
	Spikey = {Name="Spikey",Location=game:GetService("ReplicatedStorage"):WaitForChild("Ultra-Fabulous Hair")};
	Cowlick = {Name="Front Cowlick",Location=game:GetService("ReplicatedStorage"):WaitForChild("FrontCowlick")};
}
local Dummy = workspace:WaitForChild("Dummy");
local Parent = script.Parent;
local Last = Parent:WaitForChild("Last");
local Next =  Parent:WaitForChild("Next");
local HatName = Parent:WaitForChild("HatName");

Next.MouseButton1Click:connect(function()
	for i,v in pairs(Dummy:GetChildren()) do
		if v:IsA("Hat") then
			v:remove()
		end
	end
	local newhat = math.random(#hats);
	local newhatc = hats[newhat];
	newhatc.Location:Clone().Parent = Dummy;
	HatName.Text = newhatc.Name
end)

2 comments

0

It may not be 100% correct, but my guess might be to change math.random(#hats) to math.random(1,#hats)

0

that didnt work either

1 answer

I'm not completely positive, but the error's solution may be, that you need to join line 18 and 19.

local newhat = hats[math.random(#hats)]

I assume since you already define 'newhat', it already tried to get a random value. But of course, since '#hats' isn't a proper interval (a range of numbers), it errored.

1 comment

0

this is correct.

This discussion is preserved as it was. New answers, comments, and votes are closed.