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

How can I return a string of something a player said and their name?

Asked by
CodyDev 70
6 years ago

I have a monitor that is essentially a chat log, but it's not working properly. The proper message is displayed on the screen, but the username is always the player who joined the game last. I want the username to be the player who actually said the message.

What I have tried:

local screen = script.Parent.SurfaceGui
local Players = game:GetService("Players")

function moveup(t,n) --This adds the message to the screen and scrolls it up
    screen["1"].Text = screen["2"].Text
    screen["2"].Text = screen["3"].Text
    screen["3"].Text = screen["4"].Text
    screen["4"].Text = screen["5"].Text
    screen["5"].Text = screen["6"].Text
    screen["6"].Text = screen["7"].Text
    screen["7"].Text = screen["8"].Text
    screen["8"].Text = screen["9"].Text
    screen["9"].Text = screen["10"].Text
    screen["10"].Text = screen["11"].Text
    screen["11"].Text = "> [" .. n .. "] : " .. t
end

game:GetService("Players").PlayerAdded:Connect(function(p) --Part I need to fix.
    p.Chatted:Connect(function(msg)
        moveup(msg,p)
    end)
end)

I think this happens because it only listens for chatting from the first player who joined, and after somebody else joins, p is overwritten and msg is not overwritten because it's read only. Obviously, PlayerAdded is not what I should be using. So can anyone help me with this?

1
You should use a LocalScript instead of a ServerScript, this is so you can get the LocalPlayer and check if the LocalPlayer has chatted. if so, fire an event to all the clients that updates the texts or whatever you're trying to do. gmatchOnRoblox 103 — 6y
0
Thank you, this fixed the problem. CodyDev 70 — 6y

Answer this question