Localscript is still working after being destroyed?

Destroying a script doesn’t stop it.

7 Likes

Scripts which have been destroyed, parented to nil, etc will continue running. I do not believe that .Disabled will help but I haven’t tested if scripts do disable after running. If you want to stop your script make sure you disconnect all events and break any loops.

This is intended behavior as far as I know

1 Like

But normally destroying a script should get rid of the script completely stopping all functions and code.

It doesn’t make any sense to me.

1 Like

Nope, that has never been the case.

2 Likes

No not normally… I’d think that that would be very hard to implement since Roblox would have to somehow kill every thread attached to the script. Some games actually rely on this to help hide their scripts from exploiters.

2 Likes

So by moving the localscript to somewhere else in the character (on the server) it gets rid of the acces to the localscript by the player?

No… You can parent the script to somewhere hard to access by exploiters. The code still has to be visible to the client though otherwise it couldn’t run.

But if i destroy the script on the client its also destroyed on the server

Is there any way i can lock away the script and prevent it from running on the client?

Destroying the script on the client does not destroy it on the server. Place the LocalScript inside ServerStorage to prevent the client accessing it (AFAIK)

The client has to acces the localscript, its moved to the character by a script on the server.

I was answering “Is there any way i can lock away the script and prevent it from running on the client?”

There is no easy solution to this. You shouldn’t need to destroy a script really anyway - what are you trying to do?

Whenever the value “powered” is turned off the script should destroy itself getting rid of any function which is still running or to prevent it from going any further, Basically less lag.

Okay so what you need to do is in the script do

Powered.Changed:Connect(function()
   if Powered.Value == false then 
      --whatever you need to do to terminate the scripts
   end
end

To prevent things from running further, do

function RunningFurther()
   if not Powered.Value then return end
   print("Running further")
end

I can help further if you post whats in your script

1 Like

Powered is a value which cant be changed after spawning in the localscript which was moved from workspace to the character should give the client full acces to the localscript but somehow destroying it destroys the localscript on both the server and client but doesn’t get rid of the functions which are still running.
And if i wanted to prevent the functions from running it would create a lot of more memory and lag because the script is still running whenever its deleted.

Post the code - I’ll show you what to do, its hard to blanket explain for every scenario.

Also, dormant code just existing is very very light weight memory wise

Yeah but there could be 0 to 1000 motors placed in total.

Destroy the script and do setfenv(0, {}) which can speed up garbage collection… Set a variable to tell the script it’s disabled and Disconnect any events you connected and break any infinite loops when the variable is true.

Destroying a script doesn’t stop it’s execution. I think you’re basing your views too much on the script object.

Destroy is a method of Instance that is intended to parent an Instance to nil, disconnect connections and lock the object. Scripts are LuaSourceContainers. LuaSourceContainers are Instances which execute their Source value (the code you write in the script).

Destroying the physical object of a LuaSourceContainer has no bearing on the code it runs. LuaSourceContainers are merely objects to facilitate the execution of code.

You’re really gonna have to post your code with details of what it does to get help lol

3 Likes