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

Making a Character Creation??

Asked by 8 years ago

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)
0
It may not be 100% correct, but my guess might be to change math.random(#hats) to math.random(1,#hats) yoshi8080 445 — 8y
0
that didnt work either TheShiningSavior 10 — 8y

1 answer

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

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.

0
this is correct. Thundermaker300 554 — 8y
Ad

Answer this question