Why Doesn't My Script Work?

Good morning, afternoon, or night developers! I am creating a game where you can spawn in an obby from our list of obbies in game, and then you can practice it. Todo this I made a system where you find the name of the obby, you want, and then you type it into the TextBox. After this you press [Spawn] and it should clone from the replicated storage, and put it into the workspace, but I realized when I was testing that apparently TextBox.Text:Clone() does not work. But if the text in the TextBox is a currect name of an obby, then it should work. For example, the obby’s name is TheVolcano, so someone would put it in as the Text and then it would be more like local Obby = ObbiesFolder.TheVolcano:Clone() Why doesn’t it?

local ObbiesFolder = game.ReplicatedStorage:FindFirstChild("Obbies")
local TextBox = script.Parent.Parent.TextBox

ObbyAlreadySpawned = false

script.Parent.MouseButton1Down:connect(function ()
	local Obby = ObbiesFolder.TextBox.Text:Clone() --This part is the part that isnt working.
	
	if ObbyAlreadySpawned == false then
		Obby.Parent = game.Workspace
		ObbyAlreadySpawned = true
	end
	
	if ObbyAlreadySpawned == true then
		Obby:Remove()
		wait(1)
		Obby.Parent = game.Workspace
		
	end
	
end)

Here is the code.

4 Likes

you are parenting the text code to workspace… it should be in a gui in PlayerGui.

3 Likes

Its a Buildboard GUI, so wouldnt it be in the workspace?

2 Likes

Oh my mistake, I thought it was a ScreenGui, let me relook at the code and I will try to find a solution

2 Likes

No its my fault, i forgot to mention that. I also added on to the 1st message that might make it more clear.

1 Like

Can you show me the billboard gui, there may be issues with the properties of it.

2 Likes

Here its is:


CHoose

2 Likes

hmm try parenting the text to the actual surface gui.

2 Likes

Use elseif

if ObbyAlreadySpawned == false then
		Obby.Parent = game.Workspace
		ObbyAlreadySpawned = true
	end
	
	if ObbyAlreadySpawned == true then
		Obby:Remove()
		wait(1)
		Obby.Parent = game.Workspace
		
	end

This is the issue, it creates the obby, then destroys it.

3 Likes

something like this, and make sure to use elseif

local ObbiesFolder = game.ReplicatedStorage:FindFirstChild("Obbies")
local TextBox = script.Parent.Parent.TextBox

ObbyAlreadySpawned = false

script.Parent.MouseButton1Down:connect(function ()
	local Obby = ObbiesFolder.TextBox.Text:Clone()

	if ObbyAlreadySpawned == false then
		Obby.Parent = game.Workspace.ChooseObby.SurfaceGui
		ObbyAlreadySpawned = true
	elseif ObbyAlreadySpawned  then
		Obby:Remove()
		task.wait(1)
		Obby.Parent = game.Workspace.ChooseObby.SurfaceGui
                ObbyAlreadySpawned = false
	end
end)
3 Likes

Testing now… We are about to see

2 Likes

This wouldn’t work, it’s better to do this:

local obby = nil

script.Parent.MouseButton1Down:connect(function ()
	if obby then
		obby:Destroy()
	end
	
	Obby = ObbiesFolder.TextBox.Text:Clone()

	Obby.Parent = game.Workspace.ChooseObby.SurfaceGui
	ObbyAlreadySpawned = true
end)
3 Likes

Yeah it seems the other thing didnt work, I am going to try yours rq

2 Likes

Also why are you cloning Text? I’m assuming its an Instance, but why is it called Text in a TextBox?

3 Likes

One of the obbies names are TheVolcano, and so someone will type in TheVolcano, and then click Spawn, so it will clone TheVolcano i think

1 Like

So you would do:

ObbiesFolder[TextBox.Text]:Clone()

Or better yet:

local baseObby = ObbiesFolder:FindFirstChild(TextBox.Text)
if baseObby == nil then
    return
end

Obby = baseObby:Clone()
3 Likes

Wait what? What does that do? Should I change that rq?

2 Likes
  1. You can’t access textbox text from a server script.

  2. To access the object in the folder by name, you would use ObbiesFolder[TextBox.Text]

The easiest solution to this problem is to put the gui in StarterGui, set the adornee to the part, change the script to a LocalScript, then make the change I mentioned in number 2.

Hope this helps

4 Likes

May I ask what “set the adornee” means? I have never heard those terms, and how would I do so?

2 Likes

The adornee is a property of the surfaceGui, it essentially allows you to put it on a part without it being a child of said part.

2 Likes