I got this script online but it's only for 2 objects and I have 8 objects in ServerStorage.
math.randomseed(tick())
local random = math.random(1,100)
function onClick(plr)
script.Disabled = true
if random >= 1 or random <= 50 then
local item = game.ServerStorage:FindFirstChild("AR")
item:Clone().Parent = plr.Backpack
elseif random >= 51 or random <= 100 then
local item2 = game.ServerStorage:FindFirstChild("Crossbow")
item2:Clone().Parent = plr.Backpack
end
script.Parent:Destroy()
end
script.Parent.ClickDetector.MouseClick:Connect(onClick)
I tried to solve it by doing this but it didn't work...
math.randomseed(tick())
local random = math.random(1,8)
function onClick(plr)
script.Disabled = true
if random == 1 then
local item = game.ServerStorage:FindFirstChild("AR")
item:Clone().Parent = plr.Backpack
elseif random == 2 then
local item2 = game.ServerStorage:FindFirstChild("Crossbow")
item2:Clone().Parent = plr.Backpack
elseif random == 3 then
local item3 = game.ServerStorage:FindFirstChild("Grenade Launcher")
item3:Clone().Parent = plr.Backpack
elseif random == 4 then
local item4 = game.ServerStorage:FindFirstChild("Pistol")
item4:Clone().Parent = plr.Backpack
elseif random == 5 then
local item5 = game.ServerStorage:FindFirstChild("Railgun")
item5:Clone().Parent = plr.Backpack
elseif random == 6 then
local item6 = game.ServerStorage:FindFirstChild("Rocket Launcher")
item6:Clone().Parent = plr.Backpack
elseif random == 7 then
local item7 = game.ServerStorage:FindFirstChild("Shotgun")
item7:Clone().Parent = plr.Backpack
elseif random == 8 then
local item8 = game.ServerStorage:FindFirstChild("Sniper")
item8:Clone().Parent = plr.Backpack
end
script.Parent:Destroy()
end
script.Parent.ClickDetector.MouseClick:Connect(onClick)
Please help, thank you! <3

5 comments
So it's only choosing 2?
Yes and sometimes only 1
maybe u have horrible luck
why can't you just use
math.randomfor the first one?ok ill i try