Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

2 comments

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

0

No not really, you got to use the: WaitForChild() statement for things that get created later on in time.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.