Hello Forum!
I’m making a crate system, and I don’t know how to make this code “simpler.” Basically, I am detecting" if the random number equals # then" for 7 numbers meaning 7 checks which makes the code look really messy. How can I shorten this and make it cleaner? All help is appreciated. Thanks!
local Crate1 = game.Workspace.Crate1Trigger.ProximityPrompt
Crate1.Triggered:Connect(function(plr)
local cratePrice = 100
local LS = plr:FindFirstChild("leaderstats")
local Objects = game.ReplicatedStorage.Crate1
if LS.Coins.Value < cratePrice then
return
end
LS.Coins.Value = LS.Coins.Value - 100
local Items = {
knife1 = Objects.Knife1;
knife2 = Objects.Knife2;
knife3 = Objects.Knife3;
knife4 = Objects.Knife4;
knife5 = Objects.Knife5;
knife6 = Objects.Knife6;
knife7 = Objects.Knife7;
}
Objects.Crate1Bought:FireClient()
local randomNum = math.random(1, 7)
if randomNum == 1 then
-- blah blah
end
if randomNum == 2 then
-- blah blah
end
if randomNum == 3 then
-- blah blah
end
if randomNum == 4 then
-- blah blah
end
if randomNum == 5 then
-- blah blah
end
if randomNum == 6 then
-- blah blah
end
if randomNum == 7 then
-- blah blah
end
end)