Update TextBox Text for ALL Players [SOLVED]

  1. What do you want to achieve? Keep it simple and clear!
    I want to be able to type text in a team based screen gui and press on the screen gui button to update the text in a surface gui for all players to see the updated text.

  2. What is the issue? Include screenshots / videos if possible!
    The issue is that the surface gui text does update for every player BUT because the screen gui only becomes visible for players in one team, the text in every other players screen gui is empty so when the remote event fires it makes the surface gui text blank for them but for me it will show the text i put in my screengui textbox.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have not tried anything but I was thinking about somehow making my script locate only MY screengui text instead of every player in the game’s own screengui since only mine will be visible and have updated text. But idk how I would do that.
    Picture of my Explorer to show where each script is.
    Screenshot 2023-02-05 175520

Local Script

local UpdateScore = game:GetService("ReplicatedStorage").POVComps.BBComics.UpdateScore
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local Enter = playerGui.BBComics.Enter
local TextBox = playerGui.BBComics.TextBox

Enter.MouseButton1Up:Connect(function()
	UpdateScore:FireServer()
	warn("1")
end)

UpdateScore.OnClientEvent:Connect(function()
	local SurfaceGui = script.Parent.Parent
	SurfaceGui.TextLabel.Text = TextBox.Text
	warn("3")
end)

Script

local UpdateScore = game:GetService("ReplicatedStorage").POVComps.BBComics.UpdateScore

UpdateScore.OnServerEvent:Connect(function()
	UpdateScore:FireAllClients()
	warn("2")
end)

It probably isn’t recommended the best idea to do this as Exploiters might be able to fire the Event, you should Instead have a StringValue that takes in the Values for when the Value Changes, either using Changed or GetPropertyChangedSignal, for Example:

Server:

local StringValue = game.ReplicatedStorage.Status -- StringValue

StringValue.Value = "hi" -- Updates Value

Client:

StringValue.Changed:Connect(function(val) -- Changed Event
    TextLabel.Text = val -- Updates TextLabel
end)

So now, Every Player can have an Updated TextLabel, and now if a Exploiter attempts to Change to the Value, it will only do it for Themselves and not everyone.

1 Like

Oh alright, thanks! I will check out how to use this and get back to you! I haven’t used stringvalues before so imma read up on it first!

I would actually recommend you using the original system you had from before. Exploiters would be able to send messages equally as any other player anyway.

Ok, what you need to do is pass the Text of the TextBox directly into UpdateScore, and pass that back to the clients.

For example:

Enter.MouseButton1Up:Connect(function()
	UpdateScore:FireServer(TextBox.Text)
	warn("1")
end)

And then make sure to update that on the other events and on the server

Edit: TextBox* not TextLabel

1 Like

Ok i have tried this but I dont know what I am doing right. I recently learned how to transfer/pass info but Idk how to apply it here. :confused:

Can tou share your code? I can explain what you need to do. And if you have any questions about anything to do with transferring data, ask away!

1 Like

Yeah sure! So this is what I did for the Local script:

local UpdateScore = game:GetService("ReplicatedStorage").POVComps.BBComics.UpdateScore
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local Enter = playerGui.BBComics.Enter
local TextBox = playerGui.BBComics.TextBox
local BBComics = playerGui.BBComics

Enter.MouseButton1Up:Connect(function(Player)
	UpdateScore:FireServer(Player,TextBox)
	warn("1")
end)

UpdateScore.OnClientEvent:Connect(function(Player,TextBox)
	local SurfaceGui = script.Parent.Parent
	SurfaceGui.TextLabel.Text = TextBox.Text
	warn("3")
end)

and this is for the Server

local UpdateScore = game:GetService("ReplicatedStorage").POVComps.BBComics.UpdateScore

UpdateScore.OnServerEvent:Connect(function(Player,TextBox)
	UpdateScore:FireAllClients(Player,TextBox)
	warn("2")
end)

But this is the error i got:
“Players.Player1.PlayerGui.SurfaceGui.TextLabel.LocalScript:16: attempt to index number with ‘Text’ - Client - LocalScript:16”

and that line is:

SurfaceGui.TextLabel.Text = TextBox.Text

That’s odd. Trying passing the text directly instead of passing the entire TextBox instance. Like so

UpdateScore:FireServer(TextBox.Text)

(Make sure to update other endpoints)

IMPORTANT EDIT: It seems like you’re also passing the Player to FireServer. That argument is already given automatically. Remove it as shown above. You should NOT remove it from the other endpoints. (Sever and client setting the text)

Okay so it did work, BUT now the issue is that it does not copy the text, instead it shows (what I think is) random numbers? Here’s a screenshot of what I mean.


So I put “1” and pressed enter but the surfacegui shows “960” and it does this for anything else I put, even if its text. The only thing that changes is it goes from like 960 to 940, 955, 957 etc.

local plrs = game:GetService("Players")
function dosmth(fn)
	local l = plrs:GetPlayers()
	for i, v in next, l do
		local d = v:FindFirstChild("PlayerGui")
		if (d) then fn(d) end
	end
end
-- example
dosmth(function(playergui)
	-- do something
end)

That is completely unexpected. Can you check to mske sure nothing else is possibly firing this event? You can use Ctrl+Shift+F to find in multiple scripts.

Maybe you can also print the value of the textbox as well? print(TextBox.Text)

Edit: could you perhaps also post your new code?

So there is nothing else firing it and in the OutPut it does not print the Text and gives this error:

Players.AneTChrist.PlayerGui.SurfaceGui.TextLabel.LocalScript:18: attempt to index number with 'Text'

So I am guessing it is reading the “Text” as a number instead of text???

Very strange. Maybe you typed something wrong? Can you post your new code?

LocalScript

local UpdateScore = game:GetService("ReplicatedStorage").POVComps.BBComics.UpdateScore
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local Enter = playerGui.BBComics.Enter
local TextBox = playerGui.BBComics.TextBox.Text
local BBComics = playerGui.BBComics

Enter.MouseButton1Up:Connect(function(Player)
	UpdateScore:FireServer(Player,TextBox)
	warn("1")
end)

UpdateScore.OnClientEvent:Connect(function(Player,TextBox)
	local TextLabel = script.Parent
	TextLabel.Text = TextBox
	warn("3")
end)

Script

local UpdateScore = game:GetService("ReplicatedStorage").POVComps.BBComics.UpdateScore

UpdateScore.OnServerEvent:Connect(function(Player,TextBox)
	UpdateScore:FireAllClients(Player,TextBox)
	warn("2")
end)

I’ve got your answer!

The first two arguments to MouseButton1Up is

  1. The X position the mouse clicked at
  2. The Y position the mouse clicked at

You falsely named the “X” argument as “Player”

Then, you pass “Player” to FireServer

Because FireServer already adds the Player as the first argument, the server function receives: Player, X position, Text.

Because you only take two arguments, the Clients then recieve: Player as Player and X position as Text.

Solution

On the FireServer code:

  1. Remove the Player argument from the MouseButton1Up function
  2. Remove Player from FireServer, like so:
Enter.MouseButton1Up:Connect(function()
	UpdateScore:FireServer(TextBox)
	warn("1")
end)

DO NOT CHANGE ANYTHING ELSE

That should hopefully do it

Ok so i tried it but now nothing is happening :confused: the local script works, since my “1” and “3” are printing but the “2” to check my Script isn’t printing.

Alright, send the code you have now. Maybe that broke something.

Local:

local UpdateScore = game:GetService("ReplicatedStorage").POVComps.BBComics.UpdateScore
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local Enter = playerGui.BBComics.Enter
local TextBox = playerGui.BBComics.TextBox.Text
local BBComics = playerGui.BBComics

Enter.MouseButton1Up:Connect(function()
	UpdateScore:FireServer(TextBox)
	warn("1")
end)

UpdateScore.OnClientEvent:Connect(function(Player,TextBox)
	local TextLabel = script.Parent
	TextLabel.Text = TextBox
	warn("3")
end)

Server:

local UpdateScore = game:GetService("ReplicatedStorage").POVComps.BBComics.UpdateScore

UpdateScore.OnServerEvent:Connect(function(Player,TextBox)
	UpdateScore:FireAllClients(Player,TextBox)
	warn("2")
end)

WAIT! I FIGURED IT OUT! All I had to do was put

local TextBox = playerGui.BBComics.TextBox.Text

under the

Enter.MouseButton1Up:Connect(function()

So this plus removing “Player” like you told me fixed it! c:

Edit: Looks like you’ve figured it out yourself. Good job :slight_smile:

Ok, as for why 2 isn’t printing, I have no idea. But since 3 is being printed, that means that ultimately, it did work.

The reason you aren’t getting the contents of the textbox is because you’ve only saved the contents initially.

Instead of

local TextBox = BBComic.TextBox.Text

Only save the TextBox instance

local TextBox = BBComic.TextBox

Then, in your FireServer code, use TextBox.Text

UpdateScore:FireServer(TextBox.Text)
1 Like