Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make textLabel change for all players when a player presses a button?

Asked by
R0jym 47
2 years ago
Edited 2 years ago

Hello there, I made a LocalScript, a script and a RemoteEvent for my current situation that I have which is that a TextLabel changes it's text for all players to see when a player presses a button, but it does not seem to work, How do I fix this?

SERVERSCRIPT:

1local RS = game:GetService("ReplicatedStorage")
2local AnnounceEvent = RS:WaitForChild("AnnounceEvent")
3 
4AnnounceEvent.OnServerEvent:Connect(function(player)
5    AnnounceEvent:FireClient()
6end)

LOCALSCRIPT:

01local player = game:GetService("Players").LocalPlayer
02 
03local PlayerName = player.DisplayName
04local RS = game:GetService("ReplicatedStorage")
05local AnnounceEvent = RS:WaitForChild("AnnounceEvent")
06local text = player.PlayerGui.Announce.TextLabel
07local text2 = player.PlayerGui.Roll.TextLabel
08local button = player.PlayerGui.Roll.TextButton
09local value = player.PlayerGui.Roll.Value
10 
11button.MouseButton1Click:Connect(function()
12    text.Text = PlayerName..' has rolled '..text2.Text
13    AnnounceEvent:FireServer(text.Text)
14end)

2 answers

Log in to vote
0
Answered by 2 years ago

Hi there!

There is actually a very simple one.

So you can remove the Script in ServerScriptService or where you have it and the RemoteEvent.

Add a Script to the button and place this in it:

1script.Parent.MouseButton1Click:Connect(function()
2        script.Parent.Text = --your text here
3end)

A LocalScript is for the player that is seeing it so not the entire server, a Script is for the entire server.

0
Doesn't this changes the text for the StarterGui instead of the PlayerGui, plus I can't fetch the PlayerGui in the Server Script so I have to use RemoteEvents to fetch it R0jym 47 — 2y
0
No not really, you got to use the: WaitForChild() statement for things that get created later on in time. Joint_Ventures 5 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Simply, you should use remote:FireAllClients() instead of FireClient. So you should put that in your server script:

1local RS = game:GetService("ReplicatedStorage")
2local AnnounceEvent = RS:WaitForChild("AnnounceEvent")
3 
4AnnounceEvent.OnServerEvent:Connect(function(player)
5AnnounceEvent:FireAllClients()
6end)

And now you need an local script in gui that activates when announce event fires on client. If it wont work or there will be any error in output let me know.

Answer this question