Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Gui doesnt work while in PlayerGui?

Asked by 8 years ago

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?

0
What does output say? Tempestatem 884 — 8y
0
Line 2 is not a valid member of frame LittleBigDeveloper 245 — 8y
0
then line 2 isn't a valid member of 'frame' systematicaddict 295 — 8y
0
But line2 is a member of frame!!!!! LittleBigDeveloper 245 — 8y

1 answer

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
8 years ago

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)
Ad

Answer this question