So I want a certain Gui, with a script in it, to reset to it's original state. (So the script resets, and all the texts and frames are back in the original position) To do this I came up with the following script. It works once, but then it gives the following error.
ERROR: The Parent property of BackGround is locked, current parent: NULL, new parent EndGui
I know that the error is caused because I try to clone the thing that I just destroyed, but my intention is to clone the Gui as it was in the beginning of the game, when nothing changed yet. Is there any way I can do this?
script:
local BackGround = script.Parent:WaitForChild("BackGround")
local CloneBackGround = BackGround:Clone()
local NetCodeValues = game.Workspace:WaitForChild("NetCodeValues")
local Ending = NetCodeValues:WaitForChild("Ending")
Ending.Changed:connect(function(Value)
if Value then
script.Parent.BackGround.EndLocalScript.DestroyValue.Changed:connect(function(Value)
if Value then
script.Parent.BackGround:Destroy()
CloneBackGround.Parent = script.Parent
elseif not Value then
BackGround = script.Parent:WaitForChild("BackGround")
CloneBackGround = BackGround:Clone()
end
end)
end
end)

3 comments
keep a copy of it in a place like rep storage and then when you want to reset it clone it and parent it to the right place
You just need to put the ScreenGui in StarterGui and unless you have the ScreenGui's ResetOnSpawn property set to false, it should reset every time
@abnotaddable Yes, that should work, thank you! @KingLoneCat Well the problem is that it should reset when I want it to, not when a player dies... so that doesn't really help. Thx for the help guys!