local FirePicks = 0
local HowManyFires = 2
local RainPicks = 0
local HowManyRains = 2
function GenerateDigit1()
local RandomRange = math.random(0, 9) -- 0 through 9
local RandomImage = math.random(1, 2) -- # of Images
RandomDigit1.Value = tostring(RandomRange)
if RandomImage == 1 and RainPicks <= HowManyRains then -- Rain
RainPicks = RainPicks + 1
Image1.Decal.Texture = RainDropID.Value
CombinationItems.Digit1.Value = RandomDigit1.Value
ActualRain.Parent = CombinationItems
end
if RandomImage == 2 and FirePicks <= HowManyFires then -- Fire
FirePicks = FirePicks + 1
Image1.Decal.Texture = FireID.Value
CombinationItems.Digit1.Value = RandomDigit1.Value
ActualFire.Parent = CombinationItems
end
end
My combination lock is completely randomized, and it has a total of 7 digits, ranging from 0-9.
(this function is just to randomize 1 digit)
I want it to have alteast 10 different if statements, and 7 GenerateDigit() functions, so how do I make this one function more efficient?
My goal is so that I don’t need to copy and paste the if statesments 10 times, and change each one, and make 7 functions with 10 if statements within them.
I think this would work perfectly, but it needs a few changes that I don’t quite know how to do myself. RandomImage is there in my first version of my script, and that is because that would determine if it is Rain, or Fire, but since the in pairs already randomizes that, I don’t think RandomImage is necessary.
Actually don’t listen to me, the problem is not the RandomImage, because I didn’t realize what it did, it’s because the Decal didn’t load and I thought it was because of that, thank you and it worked perfectly!