Script won't change SurfaceGui

Hi! Essentially, I want to make it so when you input text into a textbox (which you need to get the input via a LocalScript) and change a SurfaceGui TextLabel. How it works - the localscript takes the input of the textbox changes the value of a StringValue in ReplicatedStorage, then the UI takes the value and puts it as the textlabel. It works perfectly for my ScreenGui, but not my SurfaceGui… Do I have to use remoteevents or something to have my SurfaceGui access them?

3 Likes

Are you trying to make the new text in the SurfaceGui visible to all players? If so, you would need to use a remote event.

2 Likes

Yes. I’m trying to make it so a player inputs some text into a TextBox (only visible to the localplayer) and it appears on a SurfaceGui (visible to all players)…
Okay, thanks. First time trying remoteevents, so let’s see how this goes.

1 Like

Sorry for replying to this again, but this is my code so far:
script.Parent.OnServerEvent:Connect(function()
script.Parent.Parent.Parent.FlightNum.Value =
end)
How would I get the player’s input into the TextBox without using PlayerGui?

1 Like

You would need to send the players input with the remote event.

So let’s say you had the remote under the variable name as FlightRemote and the Users input under the variable flightnumber you would do on the client FlightRemote:FireServer(flightnumber)

On the server side you would do this script.Parent.OnServerEvent:Connect(function(p, flightnumber) script.Parent.Parent.Parent.FlightNum.Value = flightnumber end)

The variable ‘p’ is just the Player, which you must always address as the first arguement when using OnServerEvent if you’re sending data.

Okay so I have this in my script:
script.Parent.OnServerEvent:Connect(function(p, text)

script.Parent.Parent.Parent.FlightNum.Value = text

end)

This is my localscript:
local rs = game.ReplicatedStorage
local p = script.Parent
local text = p.Text

script.Parent.FocusLost:connect(
	function(enterPressed)
		if enterPressed then
			rs.FlightNum.Value = p.Text
			rs.RemoteEvents.FlightNum:FireServer(text)
		end
	end
)

I’m not getting any errors, but the TextLabel isn’t changing.
image

Some of the code is outside of the code box, /shrug FYI

It seems like that I’ve forgotten to include the actual text label changing part of this.

So inside a server script you could do

game.ReplicatedStorage:WaitForChild(“FlightNum”).Changed:connect(function(text)
locationToTextLabel.Text = text
end)

Obviously you’ll need to replace locationToTextLabel to the path where the text label is. That way the text will update every time the value is changed.

As I already mentioned NewPuncher, you need to add a function so that when you change a value your table is updated.
.Changed:Connect(function()

I have already mentioned that I forgot to include .Changed. Mainly I was more focused on the remote dilemma.

1 Like

Yeah I still can’t get it to work. I’ve been told that you can’t change the value from the Client, but you have to change it through the server. I’m confused on your last post - are we keeping the remoteevent or is that a completely separate script?

Keep the remote event by all means as you’ll need to pass it to the server if you want everyone to see the change. My last post was just that you needed to include that little changed script so the text label can actually be changed.

Not really sure what I can do atm since I’m on mobile and it sucks trying to decently format a message.

Do you get any errors?

No errors… I got it to a point where it says nothing instead of n/a though… Getting closer…?

Never mind just realised this was a textbox not a text button

Okay, after having a bit of reading about surface guis, try reusing the same .Changed code on a local script. That should still have the same effect.

You probably want to use a button to send it to the server or wait until they press enter with FocusLost and then send it with a remote function so that the client makes sure it has gone through (and so that it cant be edited until it has). This makes it harder to spam the remote. Changed fires whenever they type anything at all into the box.

I would use a button, but they need to be able to enter the text into the textbox and have that text appear on the screen.

The changed script is connected to the string value, not the text box.

Yes. To clarify, I do that so I can easily update all the screens in the airport without having to manually update every single screen.