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

Is There a Way You Can Do Random for Objects?

Asked by 5 years ago
Edited 5 years ago

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?

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

1 answer

Log in to vote
3
Answered by 5 years ago

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 :)

0
Thanks Bro MajinBluee 80 — 5y
0
Np :) User#20388 0 — 5y
0
Congrats on 1k rep Amiaa16 3227 — 5y
0
Ty :) User#20388 0 — 5y
Ad

Answer this question