Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I destroy a local script within itself?

Asked by
dukzae 0
3 years ago

I have scripts in my game that, when triggered, clone a local script to a player's PlayerGui. After the local script has been run, I like to destroy that local script with the destroy function to clean up and remove clutter. However, it only destroys that local script from the client, not the server. I know this doesn't seem much of a problem, but I like having a clean PlayerGui and when it has LocalScripts that have already done their job, it bothers me a lot. This can also cause issues with WaitForChild and Parenting, depending on how the local script works How can I fix this?

Another question that sort of ties into this one: can I perform a server script within a local script? if so, that would make things so much easier. Thanks!

2 answers

Log in to vote
0
Answered by 3 years ago

The Local Script can only delete stuff for the Client Side so your Best to use Remote Events For the Local Script to Commuicate with a Server Script to Delete. Check here for Client To Server Scripts

Ad
Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
3 years ago

There is absolutely no need to do that. Memory is cheap. Finished scripts do not affect the performance at all.

On top of that you said that client removed their scripts. So the scripts remain in server only? In this case deleting those scripts would break the game for the next player, would it not?

I do not really understand the issue here.

Are you concerned that server sees non-existing scripts in PlayerGui? Server does not need to know what is going on in PlayerGui, if that is what you are afraid of. If it thinks the scripts are there that does not really change anything.

If script that remain in PlayerGui is an issue for other scripts, this means you are not structuring your hierarchy properly. Just to let you know, most of the time there is no need to copy scripts to PlayerGui. Put all your PlayerGui local scripts in StarterGui and just name and parent them accordingly.

Use script:Destroy() at the end if you have to, and then those scripts will only remain in StarterGui for the next player to join. But like I said there is no benefit of doing that. Its just few KB of text at worst. Most devices today have multiple GigaBytes of RAM available. And deleting script on server will probably not free up anything anyway, due to caching.

You should only be concerned with data transfer.

Answer this question