Cloned object from replicated storage refusing to go to workspace because of parent being "null"

for some reason, the code here errors out whenever I try to get the server reset object I made for my game from replicated storage to be cloned into the workspace. Heres the code:

wait(5)
local sreset = game:GetService("ReplicatedStorage").SpecialCases["Server Reset"]:Clone()

sreset.Parent = workspace


Any ideas how to fix this?

edit: In case you might assume otherwise, the script highlighted in the screenshot is the one with the current code being viewed

3 Likes

Maybe try to add an wait() before setting the parent

1 Like

Shouldn’t be necessary as long as the code above has already listed the required variable (variable has already been created, should be no error). Just in case you were right, I decided to try that anyway. It doesn’t fix anything, though.

edit: I have also tried substituting the parent of server reset from specialcases model to the replicated storage by default by changing up the code to
local sreset = game:GetService("ReplicatedStorage")["Server Reset"]:Clone()

I expected it to be a bug which is why I did this, but apparently it still did not work

2 Likes

I’d use WaitForChild() instead of wait() function. Just because wait can cause errors for players because if they have low connection it’s going to take more than 5 seconds to load the things in ReplicatedStorage.

game:GetService("ReplicatedStorage"):WaitForChild("SpecialCases")
local sreset = game:GetService("ReplicatedStorage").SpecialCases["Server Reset"]:Clone()
sreset.Parent = workspace
--or try this 
sreset.Parent = script.Parent
1 Like

Unfortunately this doesn’t work either! Any other things I could try?

1 Like

Do you get same error or different?

1 Like

Its the exact same unfortunately

1 Like

Maybe try to re-open the studio and try again because I tested script out and works on my side.
Edit: maybe it’s not working because you have errors on different scripts so make sure to fix them first.

There was an old plugin that always seemed to have an error every time it loaded. I disabled it along with all other plugins and it still doesn’t work. I doubt it’s Studio itself either but I could be wrong (for some reason every time i reopen it to edit games it actually reinstalls itself entirely, not just updating)

I reproduced the warn with this script:

workspace.ChildAdded:Connect(function(child)
	child:Destroy()
end)

Apparenty, there’s something in your game that attempts to set “Server Reset” model’s parent to nil right after you place it inside the workspace. Check other running code to find anything that could be causing this.

I actually tried an alternative method to change the parent of the cloned object by inserting it into a model from the workspace without calling for workspace itself (which is what im guessing is screwing out somehow). Here’s the code:


the thing that does not explain this situation is on whether or not it’s actually Replicated Storage that is being returned as nil; the reason why I say this is because this is a sandbox game. More specifically speaking, the “Items” file has models that get called into the workspace whenever a client requests for them (via a textbox gui you can enter in with their model name). It wouldn’t make sense to me why Replicated Storage would return nil and refuse to allow the Server Reset model from SpecialCases to be duplicated and moved into the workspace when the exact same thing is essentially occuring with the other models (from the Items folder). Also, it’s definetely not the “SpecialCases” folder as no other code I made has that name whatsoever within its lines as I have literally just created it right before this post.

edit: I also searched for “ChildAdded:Connect” in all of my scripts using the cntrl + f method but found no matches anywhere
edit 2: I’ve actually deleted the GUI system that acts as the functionality for the Items folder storage caller (puts anything from items folder into workspace) including any complimentary scripts entirely and retested it again, and it still doesn’t work!

I realize now that it is actually a stray part of code I have in the server reset model that destroys the model entirely, even if it is disabled. I have fixed this by implementing an exterior fashion of deleting the model via a workspace parented script.