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.
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.
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.
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
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.
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.
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â
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)
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)
Ok so i tried it but now nothing is happening the local script works, since my â1â and â3â are printing but the â2â to check my Script isnât printing.
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)