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

Is There a Way You Can Do Random for Objects?

I'm trying to make a crate system but i'm stuck at the Random item picker. This is the script I'm using:

local SS = game:GetService("ServerStorage")
local Items = {SS.Sword1, SS.Sword2}

script.Parent.MouseButton1Click:connect(function()
	Random.new(Items)
end)

And I know whats the problem, It needs a number argument but I gave it a table argument.

Is there a way to do a Random script for objects?

1 comment

0

Well you can't do Random.new(Items), it has to be along the lines of math.random(1, #Items)

1 answer

✓ Accepted answer

You can do this

local SS = game:GetService("ServerStorage")
local Items = {SS.Sword1, SS.Sword2}

script.Parent.MouseButton1Click:connect(function()
    local item = Items[math.random(1,#Items)]
end)

It shouldn't be to hard to understand, if you don't understand it though, just ask :)

4 comments

0

Thanks Bro

0

Np :)

0

Congrats on 1k rep

0

Ty :)

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