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

Opens and Closes once then no more? GUI

So I got a GUI working where you click it and it opens then click it again and it goes away. I am just trying to figure out how Cloning works because I know a better way to do this but I want to know how to clone things. Anyways yea it works once then stops and I got an error code too. Here is the script:

local version = script.Parent
local HUD = game.Players.LocalPlayer.PlayerGui.HUD
local More = game.ReplicatedStorage.VersionMore:Clone()
local open = false

local function onClicked()
	if open == false then
		More:Clone()
		More.Parent = HUD
		open = true
	else
		HUD.VersionMore:Destroy()
		open = false
	end
end

script.Parent.MouseButton1Down:connect(onClicked)

Now here is the error code I get: 16:13:10.088 - The Parent property of VersionMore is locked, current parent: NULL, new parent HUD

Please any help is appreciated :)

2 answers

✓ Accepted answer

In your case, More is already a clone of VersionMore, so you're cloning a clone and you're setting the parent of More in a little confused way.

You should make clones LOCALLY INSIDE THE IF STATEMENTS so it would look like

if something then
	local moreClone=More:clone()
	moreClone.Parent=whatever
end

Like that, if that if statement is processed again, it will create a new clone instead of just using the old clone.

Basically, you have to asign the clone to a VARIABLE to be able to access it. Clone() is a method, it basically creates a new instance that is completely identical to the object it is used on, as well as it's descendance. Then you can browse through its properties and children freely if it is attached to a variable (or if you simple do something:clone().Transparency=0 or something like that).

Hope my answer helped, if you need more assistance just leave a comment!

EDIT By the way, next time, make sure your question is a little more descriptive than that. Follow the guide for more info.

1 comment

0

Thanks! :D

put More inside the if open==false because it only clones once so it is gone. Just put line 03 inbetween like 07 and 08

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