Help with changing SurfaceGui TextBox text via a ScreenGui

I’m attempting to create a system that will change the text in a SurfaceGui via a ScreenGui and I’m having trouble getting the text to change, I get no errors when testing aside from the TextBox becoming blank after trying to set the new text. I’m fairly new to scripting so any and all help is welcome.

One of 3 LocalScripts in ScreenGui:

local player = game:GetService("Players").LocalPlayer
local button = script.Parent
local Event = game.ReplicatedStorage.RemoteEvent
local Value = game.ReplicatedStorage.guiMain


local function onButtonActivated()
	Value.Value = player.PlayerGui.staffGui.Frame.one.departTime.TextBox.Text
	wait(.5)
	Event:FireServer("Time")
		wait(1)
	end


button.Activated:Connect(onButtonActivated)

RemoteEvent in ReplicatedStorage along with a StringValue

Script in ServerScriptService:

local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

Event.OnServerEvent:Connect(function(player, status)
	if status == "Time" then
		game.Workspace.gateScreen.Part.SurfaceGui.flightInfo.departTime.Text = game.ReplicatedStorage.guiMain.Value
print("Time")
	elseif status == "Destination" then
		game.Workspace.gateScreen.Part.SurfaceGui.flightInfo.destination.Text = game.ReplicatedStorage.guiMain.Value
print("Destination")
	elseif status == "Number" then
		game.Workspace.gateScreen.Part.SurfaceGui.flightInfo.flightNumber.Text = game.ReplicatedStorage.guiMain.Value
print("Number")
	end
end)

For your top script you are missing an end) on your function, it should look like this:

local function onButtonActivated()
	Value.Value = player.PlayerGui.staffGui.Frame.one.departTime.TextBox.Text
	wait(.5)
	Event:FireServer("Time")
		wait(1)
	end
end --The forgotten end

There is no end missing. It is just not positioned correctly. There is no if statement or for loop.

Adding this end actually seems to create an error.

Oh my bad I thought the Event:FireServer() was an event of its own and didnt notice the poor indentation.

I suggest print debugging to check how far your code gets

For example:

local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

Event.OnServerEvent:Connect(function(player, status)
print(1)
	if status == "Time" then
print(2)
		game.Workspace.gateScreen.Part.SurfaceGui.flightInfo.departTime.Text = game.ReplicatedStorage.guiMain.Value
print("Time")
	elseif status == "Destination" then
print(3)
		game.Workspace.gateScreen.Part.SurfaceGui.flightInfo.destination.Text = game.ReplicatedStorage.guiMain.Value
print("Destination")
	elseif status == "Number" then
print(4)
		game.Workspace.gateScreen.Part.SurfaceGui.flightInfo.flightNumber.Text = game.ReplicatedStorage.guiMain.Value
print("Number")
	end
print(5)
end)

And

local player = game:GetService("Players").LocalPlayer
local button = script.Parent
local Event = game.ReplicatedStorage.RemoteEvent
local Value = game.ReplicatedStorage.guiMain


local function onButtonActivated()
print(1)
	Value.Value = player.PlayerGui.staffGui.Frame.one.departTime.TextBox.Text
	wait(.5)
	Event:FireServer("Time")
		wait(1)
	end


button.Activated:Connect(onButtonActivated)

This way you can tell exactly where your code is getting stuck

1 Like

Im not exactly sure, but the problem may be because you are changing the value of guiMain on the client side. And because of that, the server may not detect the change at all, which is why the text for the SurfaceGui is blank. You want to change the guiMain on the Server Script instead of the LocalScript.

Updated LocalScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local Event = ReplicatedStorage:WaitForChild("RemoteEvent")
local button = script.Parent

local player = Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")

local function onButtonActivated()
	wait(0.5)
	Event:FireServer("Time", PlayerGui.staffGui.Frame.one.departTime.TextBox.Text)
	wait(1)
end

button.Activated:Connect(function(onButtonActivated)

Updated Server Script:

local RS = game:GetService("ReplicatedStorage")
local WS = game:GetService("Workspace")

local Event = RS:WaitForChild("RemoteEvent")
local GuiMain = RS:WaitForChild("guiMain")
local GateScreen = WS:WaitForChild("gateScreen")

Event.OnServerEvent:Connect(function(player, Status, TextValue)
	GuiMain.Value = TextValue -- changes the value here

	if Status == "Time" then
		GateScreen.Part.SurfaceGui.flightInfo.departTime.Text = GuiMain.Value
		print("Time")
	
	elseif Status == "Destination" then
		GateScreen.Part.SurfaceGui.flightInfo.destination.Text = GuiMain.Value
		print("Destination")

	elseif Status == "Number" then
		GateScreen.Part.SurfaceGui.flightInfo.flightNumber.Text = GuiMain.Value
		print("Number")
	end
end)
1 Like