Hey, I'm completely new to Roblox Studio scripting,(And this site, this is my first post so excuse bad format please) and of course I'm no good. I've made some very basic scripts and my first test-project is to make a kind of timed bomb. One part of the code involves changing from one bleep sound per second to two bleeps per second, to three bleeps per seconds, etc... as the timer gets closer and closer to 0. However, it only seems capable of setting it to one and two bleeps per second. It does not change from two to three. My code is likely badly written and probably would create lag but that's not what I'm asking the solution to, so please don't comment about badly written code unless it is relevant. Please note how new I am to Roblox Studio. I won't know what many things are.
General Information:
I am testing in Roblox Studio's solo play - test system. I don't really mind if it does not work in an online game, this is just practise. These are regular scripts, and they are just inside a model inside a part in the workspace. No Lua errors appear however it does not work so it is technically still an error, no? The expected outcome is that the bomb beeps once per second above 25 seconds left, twice per second from 24 to 15, thrice per second from 14 to 10, etc... The outcome is that it beeps once per second above 25 seconds, and twice per second 24 to 0. (0 would be where it either explodes or hits a Critical Error, which is irrelevant to this question.) . I hope this information proves beneficial.
Things inside my bomb's model:
I have the main visual model which I assume is irrelevant as it has no scripts. I have two buttons with click detectors. I have a screen which contains the two main scripts, the Timer Script which manages the visual timer and the pause-go buttons, and the Bleep Script which manages the sounds. The Timer Script works perfectly well alone, just has no sound. If you would like me to show you what the Timer Script is, just ask. For now I will assume the problem is purely in the Bleep Script. I will show the code used to detect how many beeps should be played per second as this is where I think the problem is:
z = script.Parent.TimeLeft.Value --This is finding the time left in the bomb's timer.
function BleepSpeed()
if z >= 25 then
bleepTimes = 1
elseif z == 24 or 23 or 22 or 21 or 20 or 19 or 18 or 17 or 16 or 15 then
bleepTimes = 2
elseif z == 14 or 13 or 12 or 10 then
bleepTimes = 3
elseif z == 9 or 8 or 7 or 6 or 5 then
bleepTimes = 4
elseif z == 4 or 3 or 2 or 1 or 0 then
bleepTimes = 5
else bleepTimes = 1
end
end
the bleepTimes variable is used in extremely primitive code to play the sound a certain amoount of times. If bleepTimes = 1 then it would do one bleep per second.
This next bit of code is the loop that I use to keep ticking to the next second. Both scripts have a similar bit of code, just that one changes the visual timer while this one plays the sound.
z = script.Parent.Time.Value -This is setting the Time Left in the timer to full at the start.
keepItGoing = true --This keeps the loop checking forever.
while keepItGoing == true do
wait(0.025) --Meant to reduce lag
if Triggered == true then --If the bomb is on, not paused
if script.Parent.CriticalError.Value == false then --[[If the bomb is not experiencing an Error, which is a non-relevant part of my bomb's code]]--
CheckBleeps() --Calls the function for checking, and then playing the sounds.
wait(1 - y) --Waits one second minus the time taken to play the sounds.
end
end
end
And finally, the CheckBleeps function, which is played every second the bomb is activated.
y = 0 --This is at the start of the game, not the function, but it is relevant to this code.
function CheckBleeps()
z = z - 1
BleepSpeed()
print(z)
if bleepTimes == 1 then
script.Parent.Parent.Parent.Parent.Bleep:Play()
y = 0
elseif bleepTimes == 2 then
script.Parent.Parent.Parent.Parent.Bleep:Play()
wait(0.2)
script.Parent.Parent.Parent.Parent.Bleep:Play()
y = 0.2
elseif bleepTimes == 3 then
script.Parent.Parent.Parent.Parent.Bleep:Play()
wait(0.2)
script.Parent.Parent.Parent.Parent.Bleep:Play()
wait(0.2)
script.Parent.Parent.Parent.Parent.Bleep:Play()
y = 0.4
elseif bleepTimes == 4 then
script.Parent.Parent.Parent.Parent.Bleep:Play()
wait(0.2)
script.Parent.Parent.Parent.Parent.Bleep:Play()
wait(0.2)
script.Parent.Parent.Parent.Parent.Bleep:Play()
wait(0.2)
script.Parent.Parent.Parent.Parent.Bleep:Play()
y = 0.6
elseif bleepTimes == 5 then
script.Parent.Parent.Parent.Parent.Bleep:Play()
wait(0.2)
script.Parent.Parent.Parent.Parent.Bleep:Play()
wait(0.2)
script.Parent.Parent.Parent.Parent.Bleep:Play()
wait(0.2)
script.Parent.Parent.Parent.Parent.Bleep:Play()
wait(0.2)
script.Parent.Parent.Parent.Parent.Bleep:Play()
y = 0.8
end
end
If there is anything more that I need to add or any information you lack, or even improper fomatting for this site, please tell me. I will be checking this often.
Thank you so much for your time, even if you're just reading this :D

4 comments
You should've also told OP to use more variables on the instances, because using a lot of parents is ugly style. Apart from that, good answer. +1 upvote.
@incapaz is right, it's not necessarily "wrong" to use a lot of script.Parent.Parent.etc... but you should use variables to store them so it's easier than typing out Parent 100 times. And I'm glad it helped you out! :)
This worked perfectly, and was allot faster to write! My model sounds so much better now, and my understanding of "or" has improved! Thank you so much!
incapaz also thanks for that info :D and for chomboghai thanks for the extra info in your edit! I will use loops now, and i will remember all these shortcuts. Thanks to everyone :D