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:
01 | z = script.Parent.TimeLeft.Value |
09 | elseif z = = 24 or 23 or 22 or 21 or 20 or 19 or 18 or 17 or 16 or 15 then |
13 | elseif z = = 14 or 13 or 12 or 10 then |
17 | elseif z = = 9 or 8 or 7 or 6 or 5 then |
21 | elseif z = = 4 or 3 or 2 or 1 or 0 then |
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.
01 | z = script.Parent.Time.Value -This is setting the Time Left in the timer to full at the start. |
04 | while keepItGoing = = true do |
06 | if Triggered = = true then |
07 | if script.Parent.CriticalError.Value = = false then |
And finally, the CheckBleeps function, which is played every second the bomb is activated.
07 | if bleepTimes = = 1 then |
09 | script.Parent.Parent.Parent.Parent.Bleep:Play() |
12 | elseif bleepTimes = = 2 then |
14 | script.Parent.Parent.Parent.Parent.Bleep:Play() |
16 | script.Parent.Parent.Parent.Parent.Bleep:Play() |
19 | elseif bleepTimes = = 3 then |
21 | script.Parent.Parent.Parent.Parent.Bleep:Play() |
23 | script.Parent.Parent.Parent.Parent.Bleep:Play() |
25 | script.Parent.Parent.Parent.Parent.Bleep:Play() |
28 | elseif bleepTimes = = 4 then |
30 | script.Parent.Parent.Parent.Parent.Bleep:Play() |
32 | script.Parent.Parent.Parent.Parent.Bleep:Play() |
34 | script.Parent.Parent.Parent.Parent.Bleep:Play() |
36 | script.Parent.Parent.Parent.Parent.Bleep:Play() |
39 | elseif bleepTimes = = 5 then |
41 | script.Parent.Parent.Parent.Parent.Bleep:Play() |
43 | script.Parent.Parent.Parent.Parent.Bleep:Play() |
45 | script.Parent.Parent.Parent.Parent.Bleep:Play() |
47 | script.Parent.Parent.Parent.Parent.Bleep:Play() |
49 | script.Parent.Parent.Parent.Parent.Bleep:Play() |
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