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

Gui doesnt work while in PlayerGui?

I have a gui so when you write in it, it puts it onto a brick. This works normally when its on startergui but its for everyone so i made a script which clones it only to my inventory when i press a button.

Gui Script:

a = game.Workspace.part1.SurfaceGui.Frame.TextBox
b = game.Workspace.part1.SurfaceGui.Frame.TextBox2
c = game.Workspace.part1.SurfaceGui.Frame.TextBox3
text1 = script.Parent.Parent.line1
text2 = script.Parent.Parent.line2
text3 = script.Parent.Parent.line3
script.Parent.MouseButton1Click:connect(function()
    a.Text = text1.Text
	b.Text = text2.Text 
	c.Text = text3.Text
end)

Clone Script:

function onClicked(playerWhoClicked)
	game.ServerStorage.ScreenGui:Clone().Parent = game.Players.littelbigblox.PlayerGui
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

It clones alright but it doesnt put text onto the brick, can anyone fiquare out why?

4 comments

0

What does output say?

0

Line 2 is not a valid member of frame

0

then line 2 isn't a valid member of 'frame'

0

But line2 is a member of frame!!!!!

1 answer

✓ Accepted answer

I really hope I pinpointed the problem for you.

LocalScripts run super quick, because it's based off of the client, meaning that your computer is doing most of the work, rather than the server. Because of this, sometimes the objects in your variables are nil, because the objects themselves renders slower than your LocalScript.

To fix this, use the (:WaitForChild())[http://wiki.roblox.com/index.php?title=API:Class/Instance/WaitForChild] method. It accepts a string and waits until the object named as the said string is the child.

Gui = script.Parent.Parent.Parent
Frame = script.Parent.Parent
Button = script.Parent
Text1 = Frame:WaitForChild("line1")
Text2 = Frame:WaitForChild("line2")
Text3 = Frame:WaitForChild("line3")

Part = workspace:WaitForChild("part1")
Frame = Part:WaitForChild("SurfaceGui"):WaitForChild("Frame")

a = Frame:WaitForChild("a")
b = Frame:WaitForChild("b")
c = Frame:WaitForChild("c")

script.Parent.MouseButton1Click:connect(function()
	a.Text = Text1.Text
	b.Text = Text2.Text 
	c.Text = Text3.Text
end)

For your "Clone" script, define and see who clicks on the part first, before the GUI gets distributed.

GUI = game.ServerStorage:WaitForChild("ScreenGui")

function onClicked(playerWhoClicked)
	if playerWhoClicked.Name == "littelbigblox" then
		local GUIClone = GUI:Clone()
		GUIClone.Parent = playerWhoClicked:WaitForChild("PlayerGui")
	end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

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