Hello, how would I show the things I wrote on a textbox to a projector screen?
Example you are a author and your the only one that has access to the textbox and you write something
then it shows to everybody in the server.
Hello, how would I show the things I wrote on a textbox to a projector screen?
Example you are a author and your the only one that has access to the textbox and you write something
then it shows to everybody in the server.
you will need a remote event for that
here is the local script to put in the text box gui you currently have:
local TextBox = ----your text box
local remoteEvent = --your remote event
TextBox:GetPropertyChangedSignal("Text"):Connect(function()
remoteEvent:FireServer(TextBox.Text)
end)
A script to handle the remote event:
local remoteEvent = ---your remote event
local SurfaceGui = ----your surface gui which is in the wall i suppose
local textbox = -- your textbox which is in your SufaceGui
local Text = textbox.Text
remoteEvent.OnServerEvent:Connect(function(plr, text)
Text = text
end)
Hey, I did what you said. But I got this error in the output. Can you please help me?
Error
PlayerGui is not a valid member of Players âPlayersâ - Server - Show:5
localScript
local textbox = script.Parent.TextBox
local RS = game:GetService("ReplicatedStorage")
local ShowText = RS:WaitForChild("ShowText")
textbox:GetAttributeChangedSignal("Text"):Connect(function()
ShowText:FireServer(textbox.Text)
end)
ServerScript
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local ShowText = RS:WaitForChild("ShowText")
local textlabel = Players.PlayerGui.SurfaceGui:WaitForChild("TextLabel")
local textbox = Players.PlayerGui.ScreenGui:WaitForChild("TextBox")
local Text = textbox.Text
ShowText.OnServerEvent:Connect(function(plr, text)
Text = text
end)
these dont need player gui as you just need to put the gui from which youâve put on the part/wall from the picture youâve provided
so you mean I remove both of that?
yes
but you have the part which contain the surface gui right?
just put it like this:
local projector = ---your part in the workspace which has the surface gui
local textlabel = projector.SurfaceGui:WaitForChild("TextLabel")
local textbox = projector.ScreenGui:WaitForChild("TextBox")
it will be automaticly replicate to all player as it is in a server script
As @MrchipsMa points out, itâs best to use remote events for this. The player types the text in a local UI, and to be able to show it to other players it must go through the server.
In the example they gave, the message is sent to the server by remote event, and there it is attempted to be set as the text for the projector UI. However, again, that UI is local, and best practice is to only modify it in a localscript. For example, by again sending it through a remote event to all players.
Note that the given example only changes a variable instead of the textbox text:
local Text = textbox.Text
And that even when you do this from the server, you would need to use a loop to change the surfacegui in each players PlayerGui. I would recommend against it.
So, when a player changes the textbox, send a message to the remoteevent. On the server listen to it, and when OnServerEvent fires, take the message, and send it to all players using remoteEvent:FireAllClients(text)
Then again on the client, listen to the OnClientEvent and change the projector screen to the incoming message. As @OverDayLight points out you also want to check on the server if the player is allowed to change this projector screen. If there are multiple projector screens you will also need to keep track of which one this message is about, but that seems not the case here.
Also, donât forget itâs important to filter any text that your players can display to other players!!!
Good luck, I hope it doesnât sound too complicated, these things become much easier after youâve worked with it a few times!
Edit: Actually, technically if your surfaceUI is a child of a part in workspace (instead of in StarterGui using the âadorneeâ property), it may work setting the new text on the server once, and it will display for everyone. However, I would argue what I described is best practice. As a rule of thumb, I think its usually best to only change local things (such as UI) in localscripts.
the surfaceGui is not member of the Part. It is in StarterGui
oh ok you must have been using sort of adornee, for this you can do it like this:
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local ShowText = RS:WaitForChild("ShowText")
ShowText.OnServerEvent:Connect(function(player, text)
for _,plr in pairs(Players:GetPlayers()) do
local textlabel = plr.PlayerGui.SurfaceGui:WaitForChild("TextLabel")
local textbox = plr.PlayerGui.ScreenGui:WaitForChild("TextBox")
textbox.Text = text
end
end)
I have tried the things you said. But it doesnât work tho, like the text isnât showing on the projector screen.
man this is so complicated
-- ServerScript
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local ShowText = RS:WaitForChild("ShowText")
ShowText.OnServerEvent:Connect(function(player, text)
for _,player in pairs(Players:GetPlayers()) do
local textlabel = player.PlayerGui.SurfaceGui:WaitForChild("TextLabel")
local textbox = player.PlayerGui.ScreenGui:WaitForChild("TextBox")
textbox.Text = text
end
end)
i can say it is actually complicated but it would be more effective if you had the surface gui on the basepart instead of putting it in starterGui
i have a way to solve this.For this kind of thing,
That is not correct as although this text will sent to all players,just need to use a part to indicate what you are addressing on to the main display