Can anyone help me make code for a part that ahs surface Ui to copy what ever a person says. However, the user username msut be defiended in the script otherwise their message won’t be coppied onto the UI part screen thing.
1 Like
Do you want everyone in the game to see the updated GUI, or just the player themself?
1 Like
Everyone to see the ui ont he surface part
1 Like
In that case, you would want a Script
(server-side) parented to the same SurfaceGui
as the TextLabel
. The code would be something like:
local label = script.Parent.Label --change to your label
for _, player in pairs(game.Players:GetPlayers()) do
player.Chatted:Connect(function(message)
label.Text = player.Name.." chatted message: "..message
end)
end
Hope this helps! Let me know if you have any other issues.
2 Likes
I only want it to work so liek say if the user called “testignacc” was whtielsited then his messages would broadcast
2 Likes
am I correct in thinking you only want one player’s messages to show? If so, then it might look like:
local label = script.Parent.TextLabel --change to your label
local playersToDisplay = {} --add usernames here
local players = {}
local function updatePlayers()
local playersTable = {}
for _, player in pairs(game.Players:GetPlayers()) do
table.insert(players, player)
end
return playersTable
end
local function displayMessage()
for _, player in pairs(players) do
player.Chatted:Connect(function(message)
if table.find(playersToDisplay, player.Name) then
label.Text = player.Name.." chatted message: "..message
end
end)
end
end
game.Players.PlayerAdded:Connect(function()
players = updatePlayers()
end
This might not be the most efficient way of doing it, but I didn’t want to risk it because I’m not sure if TextChatService.OnIncomingMessage
works server-side. I hope this helps!
2 Likes