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

Filtering Enabled Problem: Allow newcomers to see changed TextLabel text?

My problem in itself is pretty easy for others but is complicated for me. That's why it's hard to come up with the question.

The problem is I want the TextLabel's text which is shown to everyone to be changed by anyone's TextBox, and it was a success but I want also the new players to see their TextLabel change by the time they come in, for example: Player A types in "Testing" on the TextBox, which changes all of the existing players in the server, the default TextLabel text is named as "Blank". So the problem is I want the new players to see it changed to "Testing" instead of getting "Blank" when they come in the server.

The script below is the Server Side Script

-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
-- References
local reciever = ReplicatedStorage.Reciever

game.Players.PlayerAdded:connect(function()
reciever.OnServerEvent:connect(function(player, args)
	local plr = player.Parent:GetChildren()
	for i = 1, #plr do
		plr[i].PlayerGui.Interface.Wrap_top.Reciever.Text = args
		wait()
		plr[i].PlayerGui.Interface.Wrap_bottom.Input.Text = ""
	end
end)
end)

I'm pretty sure the Local Script doesn't have any problems

-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
-- References
local reciever = ReplicatedStorage.Reciever

function onRecieve()
	reciever:FireServer(script.Parent.Text)
end

script.Parent.FocusLost:connect(onRecieve)

I tried doing methods like game.Players.PlayerAdded but not well executed, any suggestions?

1 answer

✓ Accepted answer

You're making this much more difficult than it needs to be. In the ServerScript for this sort of a chat, just update the StarterGui along with all the players' PlayerGuis. When a new player comes in, the client loads the Guis from StarterGui. This will also keep the message when a player dies. If you aren't sure what I mean, here's what I did to your script:

--No need to do any :GetService() functions or variables since we're only calling each one we need once

game.ReplicatedStorage.Reciever.OnServerEvent:connect(function(player, args)
	local plr = game.Players:GetPlayers() --Better to use :GetPlayers() in case the game stores something in the Players...
	for i = 1, #plr do
		plr[i].PlayerGui.Interface.Wrap_top.Reciever.Text = args
		wait()
		plr[i].PlayerGui.Interface.Wrap_bottom.Input.Text = ""
	end
	game.StarterGui.Interface.Wrap_top.Reciever.Text = args
end)

Also, to keep your code organized, try using tabs instead of spaces. I already replaced the spaces with tabs in the code snippet in this answer.

1 comment

0

Thank you so much.

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