Parent changing issue

Hey Developers!

I’m making a script where if you click a button, it will clone a folder from replicated storage and move it to workspace.
While the map is being cloned and moved, none of the scripts seem to work.

E.g: In the map, you are supposed to hit a part and be teleported. While it was working when I was building the map, it isn’t when it is cloned and moved

If you could help me that would be great! I can provide and scripts/screenshots/videos.

Thank you!

Hello, am i not sure if i got you or not, But i think you want something like this?
I tried the thing you said and yes when the script is in the ReplicatedStorage then it is moved to somewhere else where it can work, it works and prints, So i dont know what is the problem
But i suggest adding to every script the next function

script.Parent:GetPropertyChangedSignal("Parent"):Connect(function()
	print("Parent was changed")
	-- Your code
end)

Small edit
In the code, The parent which is being changed should be the Folder which is cloned, i mean if this script parent is a folder inside that folder then you will change
From

script.Parent:GetPropertyChangedSignal("Parent"):Connect(function()

To

script.Paren.Parentt:GetPropertyChangedSignal("Parent"):Connect(function()

Hope i helped you

Hello thanks for your reply!
I tried out your code and it doesn’t work.
If you’re a bit confused on what I’m trying to achieve I’ll put it here and try and see if I can try and explain it as simple as possible
When you click a button, it will clone and move a map from replicated storage into workspace
While the map correctly clones and is moved, everything with a script doesn’t work
This includes some scripts with RemoteEvents, localscripts and server scripts
When the Folder with the map and scripts is originally in Workspace (without it being cloned and moved), it works perfectly as normal.
I’m also confused as to why it’s not working because it is an exact 1:1 replica of how it would’ve been if it wasn’t cloned and moved

Okay so, you are cloning a map with scripts inside of it? if that’s the case, usually adding a cloned script or changing a parent propretie of a script will not make it work. I recommend use a script in server script service that detects when the map got cloned and then have a folder inside of it with the scripts set “disable = true”, that the map have inside. Then clone the scripts and move them to each part that needs a script of the new map and then “disable = false” each after moving each script.

Hello! Thanks for your reply!
Unfortunately your solution didn’t work.
Every time the map is cloned and moved, the scripts are also cloned and moved into their proper areas. The code still doesn’t work however.

This is what I am talking about as an example:

  • Add a new “Script” in the “ServerScriptService” and add a “Script” with “Disable = true” inside of it like this:
    ServerScriptServiceExample

  • Now Paste this code in the “Script” (ServerScriptService script one) that is not “Disabled”:

local Script = script:WaitForChild("ScriptCloning")
local Workspace = game:GetService("Workspace")


function MakingAPart()
	local Part = Instance.new("Part", Workspace)
	Part.Position = Vector3.new(-34.75, 0.5, 8.25)
	local NewScript = Script:Clone()
	NewScript.Parent = Part
	NewScript.Disabled = false
end

wait(5)
MakingAPart()
  • Now paste this code inside the “ScriptCloning” that is “Disabled”:
local Part = script.Parent

local MouseClick = Instance.new("ClickDetector", Part)

print("Starting")

MouseClick.MouseClick:Connect(function()

print("Working")

end)

Test this code, you can change the “Part” position so you can test it better.

While your code does work, how would it work in my scenario?

Do exaclty the same but with your scripts, create a script in server script service, do a function when the map got clone, add the scripts you need for the map inside the script or in a folder in server storage (its important to Disable ever script inside the ServerScriptService script one), then do this:

local NewScript = (The script you want to get move to the new map):Clone()

NewScript.Parent = (The part that works with the scripts)
NewScript.Disabled = false ---> This is really importatn, Disable needs to be at last because when we make the script Disable = false the script will run in that moment.

This is an example about how you can implement this in your game, try testing this idea in your game.

you may not want to have scripts inside the map that is being cloned, but rather have that code in scripts that are already being used.

I’ve had this problem too but I haven’t found a workaround yet

I’ll let you know if I do

actually, if you’re changing the parent of the map on the client side, then it won’t run any server scripts that are inside the map. after I tested, it seems that if you change the parent of the map on the server side then the script should start running

ok so the button that actually clones the map and changes the parent is actually using a local script
however, you’re saying that if I use a server script instead to clone the map and change the parent it will work?
if so I can easily use a RemoteEvent to communicate between the local and server-side script
I’ll test it out in the morning and see if it works!
Thanks for both of your help @Bonusizawesome @UniqJosh

1 Like

local scripts can only run in specific places. your problem could be that you’re trying to run a local script in somewhere like a map in workspace

Documentation on LocalScripts:

A LocalScript will only run Lua code if it is a descendant of one of the following objects:

  • A Player’s Backpack , such as a child of a Tool
  • A Player’s character model
  • A Player’s PlayerGui
  • A Player’s PlayerScripts .
  • The ReplicatedFirst service

if you’re trying to run a local script inside the map then it won’t work

No the local scripts work
When I was originally building the map and testing it out, everything works as normal
It’s only when the map is cloned from replicated storage and moved is when it doesn’t work.

But I’ll try testing out your original solution right now

Ok when cloning the map from a serverscript, everything seems to work.
Thanks for your help!