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

How do I make a ScreenGui in a PlayerGui change the text of a TextButton?

As I usually do, my title doesn't say much but here it is:

So I have a Surface Gui with a TextButton, once clicked it opens up a ScreenGui named 'ComputerGui' for the player that clicked it with a TextBox to type on.

It should automatically update the text of the TextButton on the SurfaceGui until the ScreenGui is closed.

The only issue is that the text isn't changing, here's the script: (The script is in the TextButton which is necessary for what I'm making)

local computerGui = script.Parent.ComputerGui
computerGui.Parent = script.Parent

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
		script.Parent.MouseButton1Click:Connect(function()
			local copy = computerGui:Clone()
			copy.Parent = computerGui.Parent
			
            copy.AncestryChanged:Connect(function(child, parent)
                print(child.Name.." is now a child of "..parent.Name)
            end)
            copy.Parent = plr.PlayerGui
            end)
		end)
	end)	
	
game.Players.PlayerAdded:Connect(function(plr)
	plr.Character:Connect(function(char)
		if plr.PlayerGui:FindFirstChild("ComputerGui")
		then
			repeat
				script.Parent.Text = plr.PlayerGui.Computer.Notepad.TextButton.Text
			until not plr.PlayerGui:FindFirstChild("ComputerGui")
		end
	end)
end)

Feel free to ask questions for more clearance.

1 answer

You are overstressing it a little. You should have the "ComputerGUI" update in a LocalScript using remoteEvents. Assume that you have a RemoteEvent in ReplicatedStorage.

Script 1 (ServerScript):

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		RemoteEvent:FireClient(plr)
	end)
end)

If you want to have the text only appear once OnPlayerAdded, consider using the method down below.

Script 1 (Solution 2):

game.Players.PlayerAdded:Connect(function(plr)
	-- Waiting for the character to load.
	repeat wait() until workspace:WaitForChild(plr.Name)
	RemoteEvent:FireClient(plr)
end)

You can now update your text via LocalScript.

Script 2 (LocalScript):

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

RemoteEvent.OnClientEvent:Connect(function()
	GUI.Frame.Visible = true

	-- You can have your text changed here.
	
	-- You can also have your text close here.
	GUI.Frame.Visible = false

	-- If you want to send another message to the server, you can do so by using a remote event.
	RemoteEvent:FireServer()
end)

1 comment

0

I am not sure if I understand, also the GUI self-destruct once closed.

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