So this script is suppose to either give you a silenced smg or a baseball bat but it only gives the baseball bat even when i made the silenced smg chance higher, any solutions?
math.randomseed(tick())
local random = math.random(1,100)
function onClick(plr)
script.Disabled = true
if random >= 1 or random <= 50 then
local item1 = game.ServerStorage.LootTable["Baseball Bat"]
item1:Clone().Parent = plr.Backpack
elseif random >= 1 or random <= 100 then
local item2 = game.ServerStorage.LootTable["Silenced SMG"]
item2:Clone().Parent = plr.Backpack
end
script.Parent.Parent.Parent.Parent:Destroy()
end
script.Parent.Triggered:Connect(onClick)
Change the “or”'s to “and”'s. Also, move the random into the onClick function.
math.randomseed(tick())
function onClick(plr)
local random = math.random(1,100)
if random >= 1 and random <= 50 then
local item1 = game.ServerStorage.LootTable["Baseball Bat"]
item1:Clone().Parent = plr.Backpack
elseif random > 50 then
local item2 = game.ServerStorage.LootTable["Silenced SMG"]
item2:Clone().Parent = plr.Backpack
end
script.Disabled = true
script.Parent.Parent.Parent.Parent:Destroy()
end
script.Parent.Triggered:Connect(onClick)
math.randomseed(tick())
function onClick(plr)
local random = math.random(1,100)
if random >= 1 and random <= 90 then
local item1 = game.ServerStorage.LootTable["Baseball Bat"]
item1:Clone().Parent = plr.Backpack
elseif random > 90 then
local item2 = game.ServerStorage.LootTable["Silenced SMG"]
item2:Clone().Parent = plr.Backpack
end
script.Disabled = true
script.Parent.Parent.Parent.Parent:Destroy()
end
script.Parent.Triggered:Connect(onClick)
Also, in this case, you could really just use an else statement since there are only 2 items.
math.randomseed(tick())
function onClick(plr)
local random = math.random(1,100)
if random >= 1 and random <= 90 then
local item1 = game.ServerStorage.LootTable["Baseball Bat"]
item1:Clone().Parent = plr.Backpack
else
local item2 = game.ServerStorage.LootTable["Silenced SMG"]
item2:Clone().Parent = plr.Backpack
end
script.Disabled = true
script.Parent.Parent.Parent.Parent:Destroy()
end
script.Parent.Triggered:Connect(onClick)
math.randomseed(tick())
function onClick(plr)
local random = math.random(1,100)
if random >= 1 and random <= 90 then
local item1 = game.ServerStorage.LootTable["Baseball Bat"]
item1:Clone().Parent = plr.Backpack
elseif random > 90 and random <= 99 then
local item2 = game.ServerStorage.LootTable["Silenced SMG"]
item2:Clone().Parent = plr.Backpack
elseif random > 99 then
local item3 = game.ServerStorage.LootTable["item"]
item3:Clone().Parent = plr.Backpack
end
script.Disabled = true
script.Parent.Parent.Parent.Parent:Destroy()
end
script.Parent.Triggered:Connect(onClick)
Also, you really don’t need to rename the variable each time they could all be called “item”, but to go with how you were doing it I named it “item3”
Also, I know that this is already solved, but you could make this much more simpler by doing something like this:
local items = {
["Baseball Bat"] = {
chance = 90,
path = game.ServerStorage.LootTable["Baseball Bat"]
},
["Silenced SMG"] = {
chance = 9,
path = game.ServerStorage.LootTable["Silenced SMG"]
},
["Item"] = {
chance = 1,
path = game.ServerStorage.LootTable["Item"]
},
}
local totalchance = 0
for i,v in pairs(items) do
totalchance += v.chance
end
function onClick(plr)
local random = math.random(1, totalchance)
local currentchance = 0
for i,v in pairs(items) do
currentchance += v.chance
if random <= currentchance then
v.path:Clone().Parent = plr.Backpack
break
end
end
script.Disabled = true
script.Parent.Parent.Parent.Parent:Destroy()
end