#loop script (beginner)
119 messages · Page 1 of 1 (latest)
hey, could you send your script?

just 15 minutes in seconds lol
yeah
im really bad at scripting sry
nah it's okay don't worry
but im just trying to learn it
I'm a beginner too
ok I guess you would need a bool to check and change the value of the sandstorm particles
bool???
I don't really know how to use repeat but I guess in your case you don't need for it to end right?
nope, it just has to go on forever
so you could use
while true do
-- your script here
end
it never becomes false in this case
but the sandstorm is only for 3 minutes and then there is no one for 15 minutes
ohh I see
it would still work I think
all right let's start by adding a variable that's a boolean
for example
local isEnabled = false -- (or true if you want it to run instantly?)
uhhh
** You are now Level 3! **
uhh, now what?
aight
now add a variable to get the particles of the sandstorm (you'll see it's quicker than to call workspace.SandStorm.... everytime)
k
i did that
ok good
now what
now you can start the while true loop
okok good
oh wait
I guess we don't even need the boolean since the loop checks every frame
oh okay
local isEnabled = false
local SandStorm = workspace.SandStorm.ParticleEmitter
while true do
wait(900) -- wait 15 minutes (you could put less to try the script out)
SandStorm.Enabled = true -- particles play
wait(180) -- waits 3 minutes)
SandStorm.Enabled = false
end
I guess?
oh
** You are now Level 6! **
idk why
oh wait
k
hmm
I guess try going to
FILE (up left corner)
roblox settings
well studio settings
and try searching for debugger
and check off debugger enabled maybe
if it doesn't work then idk
thx
no it's 21
lol
@lusty patrol Idk how new you are so ig I'll just do an intro to loops for you.
Loops:
loops, as in the name, will repeat actions until told otherwise. To make an infinite loop (A loop that lasts forever), use a while loop while true do, this will check a condition and if true, will loop.
In @rain canopy example, he has a loopthat waits every 15 minutes and makes a particle enabled, then after 3 minutes, it will stop. While this works, there are some other things that need to be said about it.
Since loops are infinite, if this needs to be stopped by any means, use break to stop a loop. If a condition doesn't meat your standards but you do not want the loop to stop, use continue.
Task scheduler:
wait() is deprecated. It runs at 30htz and is NOT officially recomended anymore, use task.wait().
One problem about his example is a variable named isEnabled. He never uses it so it's waste of memory
local SAND_STORM_DURATION = 60 * 15 --15 minutes
local SAND_STORM_COOLDOWN = 60 * 3 --3 minutes
local sandStormParticle = ...
while true do
task.wait(SAND_STORM_DURATION)
sandStormParticle.Enabled = true
task.wait(SAND_STORM_COOLDOWN)
sandStormParticle.Enabled = false
end
I kinda said it wasn't necessary since it's a loop 🗣️
but yeah I agree on the optimization
I didn't go into too much detail about loops so mb ig
@rain canopy check ur help page
what if i want it to have a sound when its on?
you could create a Sound object
yeah i already did that
ok
so get the sound path in the script
like local SandstormSound = bla bla bla
then after it's either enabled or disabled
you write SandstormSound:Play() or SandstormSound:Stop()
taking snicka's script uhh
local SAND_STORM_DURATION = 60 * 15 --15 minutes
local SAND_STORM_COOLDOWN = 60 * 3 --3 minutes
local sandStormParticle = ...
local sandStormSound = ...
while true do
task.wait(SAND_STORM_DURATION)
sandStormParticle.Enabled = true
sandStormSound:Play()
task.wait(SAND_STORM_COOLDOWN)
sandStormSound:Stop()
thx
i just found out the particle emitter got deleted
so i just have to fix that
oh wait
** You are now Level 4! **
it didnt