Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Ways to make a script run code only AFTER it's been cloned?

hello,

im trying to create a script that, once it's cloned into a specific folder, runs it's script.

currently, the game creates a folder (folder A) within an already existing folder (folder B) in ServerStorage, then clones a script into folder A. the script starts with:

local ServerStorage = game:GetService("ServerStorage")

if script.Parent.Parent.Parent == ServerStorage then
--script here
end

which, is not only extremely embarrassing to post and grossly inefficient, but also doesn't work. surprise surprise.

im still very new to this. i am looking up tutorials and checking the API when i can but i cant find anything that could help me in this regard. whats worse is that this has actually worked before - when cloning a simple object into the workspace that had a script attached that checked if it was in the workspace, then fired its script. but its not working for this more complex script.

i dont know what to do. im sure there are better ways of doing what i want to, and even of doing it in this manner, but i just dont know. any feedback or ideas would be fantastic.

thank you in advance.

PS: im sorry you had to read that script abomination

2 answers

If you keep the script inside of the replicated storage service it will not run until cloned, and parented somewhere else.

You shouldn't be looking into API's to find an answer to this query of yours.

Anyways, try the code below.

script.Parent.Parent:GetPropertyChangedSignal('Parent'):Connect(function()
if script.Parent.Parent.Parent == game:GetService('ServerStorage') then
--script here
end

I'm not sure that Parent is a proper argument for the GetPropertyChangedSignal, as the Parent property isn't a StringValue (per say).

Please let me know is the code works. If it doesn't then I'd be happy to provide an alternative solution to your issue.

3 comments

0

If*

0

thank you so much for the response. ive been stuck on how to solve this problem for a while now. i know checking the api reference probably isnt the right way to learn lua, but ive just been doing what i can to learn more here and there. unfortunately, the code snippet didn't work - however it may still be the thing that im looking for. from what i could gather (from the api reference, lel)

0

it checks if the specified value of an instance has changed, correct? either way, thank you for your help.

This discussion is preserved as it was. New answers, comments, and votes are closed.