Localscript is still working after being destroyed?

I have noticed the motors in the screenshots below still functioned after the script was destroyed and was checking with some prints to find out what caused this, But instead i saw that the script still functioned after being destroyed.

On the server it says its destroyed.
image

Same thing for the player.
image

The destroying function (on the local script) :
if Block.Configuration[“Powered”].Value == false then
Motor.ActuatorType = None
Motor.LimitsEnabled = false
print(Destroyed)
wait()
script:Destroy()
print(scriptwasdestroyed)
end

https://gyazo.com/9a89da2441eb9b5b3aab77e62b5d1c21.gif

The local script is inside of the block that was cloned by a serversided script to workspace and the local script is moved by a script on the server to a folder in the character and then enabled.
and whenever powered is turned off the script destroys itself.

image
after being destroyed it prints nil as its parent.

Does anyone know why this occurs? And what do i do to prevent this from happening?

2 Likes

A post was merged into an existing topic: Off-topic and bump posts

1 Like

The server can’t delete local scripts on the client.
(That is if the script is given via StarterGui)

1 Like

The script is deleted on the local script but moved on the server side

This could be because you’re not disabling the script with BaseScript.Disabled, just destroying it. All calling Instance:Destroy does is parent the Instance to nil, lock the parent property, and disconnect all connections.

4 Likes

Might want to end any threads in there before

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