#loop script (beginner)

119 messages · Page 1 of 1 (latest)

lusty patrol
#

hello iam a beginner scripter, and i really wanted my sandstorm to start every 15 minutes. But the loop doesnt work? so the sandstorm has to be there for 3 minutes then go away come back 15 minutes later and then loop ofc. Can anybody help? :D

rain canopy
lusty patrol
#

it doesnt need to say 10

distant crown
lusty patrol
#

just 15 minutes in seconds lol

rain canopy
#

damn.

#

soo 900 then

lusty patrol
#

yeah

rain canopy
#

uhh aight

#

I don't even know where to start 😭

lusty patrol
#

im really bad at scripting sry

rain canopy
#

nah it's okay don't worry

lusty patrol
#

but im just trying to learn it

rain canopy
#

I'm a beginner too

#

ok I guess you would need a bool to check and change the value of the sandstorm particles

lusty patrol
#

bool???

rain canopy
#

uhh

#

true or false

lusty patrol
#

k

#

but how do i make it loop

rain canopy
#

I don't really know how to use repeat but I guess in your case you don't need for it to end right?

lusty patrol
#

nope, it just has to go on forever

rain canopy
#

so you could use

while true do
  -- your script here
end
lusty patrol
#

but what about when its false?

#

and right now my script doesnt turn off

rain canopy
lusty patrol
rain canopy
#

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?)

lusty patrol
#

uhhh

worldly snowBOT
#

studio** You are now Level 3! **studio

lusty patrol
#

uhh, now what?

rain canopy
#

aight

#

now add a variable to get the particles of the sandstorm (you'll see it's quicker than to call workspace.SandStorm.... everytime)

lusty patrol
#

k

rain canopy
#

something like

#

local SandstormParticles = workspace.SandStorm.ParticleEmitter

lusty patrol
#

i did that

rain canopy
#

ok good

lusty patrol
#

now what

rain canopy
#

now you can start the while true loop

lusty patrol
#

this is it btw

rain canopy
#

okok good

#

oh wait

#

I guess we don't even need the boolean since the loop checks every frame

lusty patrol
#

oh okay

rain canopy
#

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?

lusty patrol
#

testing

#

Its says Rendering is paused for debugging

rain canopy
#

oh

worldly snowBOT
#

studio** You are now Level 6! **studio

lusty patrol
#

idk why

rain canopy
#

oh wait

lusty patrol
#

k

rain canopy
#

go to "script" at the very top of the screen

#

is this on never?

lusty patrol
#

its on never

#

already

rain canopy
#

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

lusty patrol
#

okay

#

i clicked it off

rain canopy
#

if it doesn't work then idk

lusty patrol
#

IT WORKS

#

Thank You So Much!

rain canopy
#

OH NICE :D

#

no problem !!

#

I'm here if you need anything else

lusty patrol
#

thx

warm bronze
#

2+2 is fish

rain canopy
lusty patrol
#

lol

rain canopy
#

could anyone help for my issue please??

severe sedge
#

@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
rain canopy
#

but yeah I agree on the optimization

severe sedge
#

I didn't go into too much detail about loops so mb ig

#

@rain canopy check ur help page

lusty patrol
rain canopy
lusty patrol
#

yeah i already did that

rain canopy
#

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()
lusty patrol
#

thx

#

i just found out the particle emitter got deleted

#

so i just have to fix that

#

oh wait

worldly snowBOT
#

studio** You are now Level 4! **studio

lusty patrol
#

it didnt

rain canopy
#

oh

#

yeah you have to replace the ...

#

ig

lusty patrol
#

wait how do i make it so i can test it

#

my math isnt mathing

rain canopy
#

change it to like 5 or 10 seconds each

#

if you wanna keep this form I guess you can do

#

60 / 10

#

and uhh 60 / 6 idk

#

whatever

lusty patrol
#

the sound stops every 10 seconds but the storm doesnt

#

oh wait