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
1 year ago
Edited 1 year 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:

local RS = game:GetService("ReplicatedStorage")
local AnnounceEvent = RS:WaitForChild("AnnounceEvent")

AnnounceEvent.OnServerEvent:Connect(function(player)
    AnnounceEvent:FireClient()
end)

LOCALSCRIPT:

local player = game:GetService("Players").LocalPlayer

local PlayerName = player.DisplayName
local RS = game:GetService("ReplicatedStorage")
local AnnounceEvent = RS:WaitForChild("AnnounceEvent")
local text = player.PlayerGui.Announce.TextLabel
local text2 = player.PlayerGui.Roll.TextLabel
local button = player.PlayerGui.Roll.TextButton
local value = player.PlayerGui.Roll.Value

button.MouseButton1Click:Connect(function()
    text.Text = PlayerName..' has rolled '..text2.Text
    AnnounceEvent:FireServer(text.Text)
end)

2 answers

Log in to vote
0
Answered by 1 year 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:

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

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 — 1y
0
No not really, you got to use the: WaitForChild() statement for things that get created later on in time. Joint_Ventures 5 — 1y
Ad
Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

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

local RS = game:GetService("ReplicatedStorage")
local AnnounceEvent = RS:WaitForChild("AnnounceEvent")

AnnounceEvent.OnServerEvent:Connect(function(player)
AnnounceEvent:FireAllClients()
end)

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