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

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

Asked by 3 years ago

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

Log in to vote
1
Answered by 3 years ago

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

Ad
Log in to vote
0
Answered by
zane21225 243 Moderation Voter
3 years ago

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.

0
If* zane21225 243 — 3y
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) Keleindor 9 — 3y
0
it checks if the specified value of an instance has changed, correct? either way, thank you for your help. Keleindor 9 — 3y

Answer this question