I'm working on a game that bases on chests.
What's supposed to happen is that when the chest is clicked, it spawns a random weapon.
local item1 = math.random(1, 4)
function onClicked()
if item1 == 1 then
local paintballGun = game.ReplicatedStorage.ClassicPaintballGun1:Clone()
paintballGun.Parent = game.Workspace
elseif item1 == 2 then
local normalSword = game.ReplicatedStorage.ClassicSword1:Clone()
normalSword.Parent = game.Workspace
elseif item1 == 3 then
local laserGun = game.ReplicatedStorage.LaserGun1
laserGun.Parent = game.Workspace
elseif item1 == 4 then
local rpg = game.ReplicatedStorage.RPG1
rpg.Parent = game.Workspace
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
For some reason, it only spawns "laserGun", every single time. I'm not sure what to do. and when i change math.random(1, 4) to math.random(0, 4), it only spawns "normalSword". All these weapons are in ReplicatedStorage, and this script is on the chest.

2 comments
Thanks, it worked!
If you want to shorten calling math.random(...), you might be able to do something like "r = math.random" followed by "r(1,4)".