How do I stop a script?

Hello! I’m Crunchy!
I’m trying to achieve a weathering/rain system.

I’m trying to learn how I stop a script. (stop rain)

If anyone can help, Thank you!

EDIT:

The script can’t be destroyed, or removed. Since it needs to loop again after.

5 Likes

disabling the script will suffice

--from another script
rainscript.disabled = true
5 Likes

You could destroy the script by using script:Destroy(), that would probably be the most simple way to do it. Good luck!

3 Likes

When i use the *string, i enter the game and then the folder containing the script. So with the script dissapears… Help?

Your post does not make sense to me. Please try to put more detail in what you’re trying to say so that I can understand.

1 Like

If the script is in SSS, then it doesn’t show because you are looking from the client, and you can’t see SSS.

Alright so I have my script…

random idea of script:

wait(4)
 [random mumbo jumbo about it spawning etc)
end
wait(5)
script:Destroy()

When I enter the game. OR Test the game The folder, that has the script in it. Just dissapears, it isn’t there. Help me please.

BUT:
Then again, i also want it to loop and start the script again… SO i don’t want the script to not exist.

2 Likes

Try what @InternallyAmplified suggested to do.

1 Like

It didnt do anything.
keeps the scritp running.

1 Like

Is your rain script a loop? if you disable a script that contains a loop, I don’t think that it will stop, can you please post your entire code?

2 Likes

don’t know how to loop, thats a compeltly different topic… I need a script that will allow me though

1 Like

The thing is you have to provide more information to know what you want

Heres what im thinking:

your script here
wait(3)
local chosen = math.random(1, 20) -- if you want it to restart raining after a random time
script.Disabled = true
wait(chosen) -- can put any number instead of chosen to put a certain time instead of random
script.Disabled = false
1 Like

but in the start of your forum post you pertained to say:

So i’m very confused right now

again it would help heaps if you pasted your entire script here :slight_smile:

Why not just have the weather system be a series of functions? then have a variable getting toggled whenever the function should/shouldn’t be used

1 Like
wait(math.random(600,300))

while wait(.01) do

local rainpart = game.ReplicatedStorage.RainPart.RainPart:Clone()

rainpart.Parent = game.Workspace.RainPart

rainpart.Position = Vector3.new(math.random(-200,500),500,math.random(-200,500))

rainpart.CanCollide = false

end

directory:


https://gyazo.com/292c810bad1b735f1aa87eed9db0e74c

1 Like

here ill try to make the code for you, i’ll use a random time limit

local rainimage = "rbxassetid://" --image id after the //
local sky = Instance.new("Part", game.Workspace)
sky.Size = Vector3.new(100, 1, 100)
sky.Position = Vector3.new(0, 100, 0)
local rain = Instance.new("ParticleEmitter", sky)
rain.EmissionDirection = "Bottom"
rain.Transparency = '0.3'
rain.Texture = rainimage
rain.Enabled = false
while true do
local chosen = math.random(60, 180) --it can rain from a minute to 3 minutes
local waitbeforenext = math.random(120, 600) --it stops raining from 2 minutes to 10 minutes
rain.Enabled = true
wait(chosen)
rain.Enabled = false
wait(waitbeforenext)
end

there i hope that can help you achieve what you need to achieve :slight_smile: you do not even need to disabled the script, just disable the particle thing, if thats what you are going to use. have a nice day :slight_smile: tell me if you need more help

1 Like

I was even thinking of a more simpler approach in just creating a function:

function RainOn (Toggle)
	repeat wait(0.01)

		local rainpart = game.ReplicatedStorage.RainPart.RainPart:Clone()

		rainpart.Parent = game.Workspace.RainPart
		
		rainpart.Position = Vector3.new(math.random(-200,500),500,math.random(-200,500))
		
		rainpart.CanCollide = false
		
	until
	
Toggle == false
end

RainOn(true) -- turns on rain
wait() -- how much you wanna wait
RainOn(false) -- turns off rain

Then you can use “RainOn(true/false)” as many times as you want

EDIT: You can even make the rain fall continuous by adding another loop at the very bottom:

while wait(0.01) do
RainOn(true)
wait(math.random(600,300))
RainOn(false)
end
2 Likes

Hang on im not sure if he wants like a tiny rain effect or actual block drops XD
Block drops would make the game VERYYYY laggy, especially one every 0.01 seconds, wich is 100 per second. I would suggest maybe a bit slower or my solution. No offense of course but try to think of the number of objects you are creating. And depending on the size of the map you may need less if its a small map or more if its a big map so. I defenitely do NOT recommend having this in a big map like apocalypse rising for example. Cause then you would need, if you want like a good amount of rain, tons of blocks everywhere in the map or even particles, im not sure but i think particles are only visible within a certain radius too.

2 Likes

I am well aware of the product of the script however, my script is just showing him how he can make a script like his own function. Yours ended up changing his code entirely which may have confused him.

I wanted to keep it simple so he could learn a bit more.