I’m trying to write a script like this:
game.StarterGui.ScreenGui.TextLabel.Text = "Intermission"
But, as you may have guessed it doesn’t work. The text doesn’t change. How do I fix this?
I’m trying to write a script like this:
game.StarterGui.ScreenGui.TextLabel.Text = "Intermission"
But, as you may have guessed it doesn’t work. The text doesn’t change. How do I fix this?
I believe you could do a pairs loop and go through everyones UI as to change it that way, but I believe firing a remote and handling it on the client would just be more efficient and less likely to break.
The reason is that you’re looking through the StarterGui not the PlayerGui. I’d recommend putting a script inside the TextLabel and using script.Parent
rather than game.StarterGui.ScreenGui.TextLabel
Great suggestion! However, if I use a remote event, then exploiters will be able to put what ever they want on the player’s screen, sadly. That’s why I’m not doing that.
This sounds like it could work. However, because I’m fairly new to scripting, I don’t know how to do this yet. Would you mind explaining?
If you want an explanation for Remote Events then I highly suggest this article : Bindable Events and Functions | Roblox Creator Documentation
If you are firing the remote from the server to the client, i.e server → client communication, an exploiter cannot interfere with that unless they have previously had access to that script.
However, the loop would look something like such:
local playerService = game:GetService("Players")
for _, v in pairs(playerService:GetPlayers()) do
v.REFERENCE_TO_TEXTLABEL_HERE.Text = "Intermission"
end
or alternatively,
-- Server
game:GetService("ReplicatedStorage").Remote:FireAllClients("Intermission")
-- Client
local UIText = script.Parent
game:GetService("ReplicatedStorage").Remote.OnClientEvent:Connect(function(text)
UIText.Text = text
end)
(Obviously you should define the remote, I was just lazy)
Like Haso said, it’s because you are editing the UI inside the StarterGui object, which once cloned into a PlayerGui, does not replicate changes across all players.
You need to loop through the PlayerGui’s of each player in game using a for loop and game:GetService(“Players”):GetPlayers() as the table.
What is “playerService”
Just for the sake of learning.
You first have to make a for loop and iterate every single player’s GUI, then just get the TextLabel.Text
property to set the text to your desired text.
Normally, playerService would be nil since it isn’t a reserved keyword (like function
) or variable name. However, on the first line I defined it as game:GetService("Players")
, which gets the player service, hence the name.
I didn’t see the variable on the first line
Thanks.
This doesn’t work on the client or the server. I’m probably missing something blatantly obvious.
yea fireallclients can only be fired from the server and unless u obtain a fireserver from a client then do the change, an exploiter cant do anything regarding this.
also to change gui u can use fireallclients or getpropertychangedsignal just look into the api documentation
Not really, they can just edit the parameters and this is a RemoteEvent fired on Server, so it makes no sense. (Btw even if there is not a single script they will be able to put whatever they want on their screen, since ScreenGuis are local)
I would recommend using :FireAllClients()
, because if you handle this on the server it could break something.
You could just make a server script fire a remote event to all clients using :FireAllClients
, there really is no need for for
loops, unless you want only a few people to have the change in gui, if you did needed that, then I suggest you change the title to that.
I didn’t read what @Sarchyx said before I posted this, so yeah read what he said too.
You should use a RemoteFunction and use the FireAllClients in your script, maybe that could help. Not too experienced with that yet ^
do
plr.PlayerGui.ScreenGui.TextLabel.Text = “Intermission”
instead