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

Script not working correctly in ServerScriptService?

Asked by 4 years ago
Edited 4 years ago

The chat bubble popped up as expected, but I wanted to try adding a 'chat' to the chat gui just to make it look like the certain player actually said it, but for some reason the script I used didn't work?

game.ReplicatedStorage.ChatEvent.OnServerEvent:Connect(function(player, plr, text)
    local g = text
    for i = 1, (28 + string.len(plr.Name)) do
        g = " "..g
    end
    game.Chat:Chat(plr.Character.Head, text, "White")
    for i, players in ipairs(game.Players:GetPlayers()) do
        local frame = game.ReplicatedStorage.Frame:Clone()
        frame.Parent = players.PlayerGui:WaitForChild("Chat").Frame.ChatChannelParentFrame.Frame_MessageLogDisplay.Scroller
        frame.TextLabel.Text = g
        frame.TextLabel.TextButton.Text = "["..plr.Name.."]:"
    end
end)

When the remote event gets fired, it either tells me 'Chat is not a valid member of PlayerGui' and when I did WaitForChild("Chat") as in the above script, it just puts me in an infinite wait time even if the chat gui is clearly already a part of PlayerGui.

Is there something about the Chat screengui that I didn't know about or??

Answer this question