Chat is not a valid member of PlayerGui

im making a custom chat thinging and its erroring Chat is not a valid member of PlayerGui
script: ```
local Players = game:GetService(“Players”)
local LocalPlayer = Players.LocalPlayer
local function RemoveSpaces(String)
return String:gsub("%s+", “”) or String
end

local function FindPlayer(String)
String = RemoveSpaces(String)
for _, _Player in pairs(Players:GetPlayers()) do
if _Player.Name:lower():match(’^’… String:lower()) then
return _Player
end
end
return nil
end

game.Players.PlayerAdded:Connect(function(player)
playertochat = FindPlayer(player.Name)
playertochat.PlayerGui.Chat.Frame.ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar:CaptureFocus()
playertochat.PlayerGui.Chat.Frame.ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar.Text = “I Like Almonds”
playertochat.PlayerGui.Chat.Frame.ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar:ReleaseFocus(true)
end)

1 Like

Try using PlayerGui:WaitForChild("Chat") instead.

1 Like

Infinite yield possible on ‘Players.mlnitoon2.PlayerGui:WaitForChild(“Chat”)’

1 Like

That’s because you need to play test the game with your player instead of running it.

While testing your game, open Players > (your name) > PlayerGui, and make sure that there is a Chat Gui like the following:
image

If there isn’t, then another script could be removing the chat, or you simply have chat turned off for your experience.

i did playtesty the game with my player

the chat is there. how is this haopen

For the second argument, put 5 as the max wait time.

PlayerGui:WaitForChild(“Chat”, 5)

It doesn’t see the frame as an object, weird.

ServerScriptService.Script:19: attempt to index nil with ‘Frame’ its now not detecting the frame

Try using WaitForChild for the frame also.

Your script is so confusing, why are you getting LocalPlayer at the top of the script? You literally have a player argument at the PlayerAdded function so why do you then fire the FindPlayer function if you literally already have the player object? Are you sure FindPlayer is even returning something?

Is your script a serverside Script? only LocalScripts can see your Chat.

2 Likes

lmao what ServerScriptService.Script:19: attempt to index nil with ‘WaitForChild’

. ohhhhhhhhhhhhhhhhhh im stupid

That happens to me sometimes lol, Roblox Studio indexing everything with nil, good times.

index nil with game imagine LOL

You should use a RemoteEvent to tell the server what Chat is from a LocalScript.

Players.mlnitoon2.PlayerGui.LocalScript:17: attempt to index nil with ‘Name’ line: local playertochat = FindPlayer(player.Name) localscript: true

i fixed alot and now its not working and no errors
localscript local Players = game:GetService(“Players”)
local function RemoveSpaces(String)
return String:gsub("%s+", “”) or String
end

local function FindPlayer(String)
String = RemoveSpaces(String)
for _, _Player in pairs(Players:GetPlayers()) do
if _Player.Name:lower():match(’^’… String:lower()) then
return _Player
end
end
return nil
end

game.ReplicatedStorage.SendChat.OnClientEvent:Connect(function()
local playertochat = game.Players.LocalPlayer
playertochat:WaitForChild(“PlayerGui”,5):WaitForChild(“Chat”):WaitForChild(“Frame”).ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar:CaptureFocus()
playertochat:WaitForChild(“PlayerGui”,5):WaitForChild(“Chat”):WaitForChild(“Frame”).ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar.Text = “I Like Almonds”
playertochat:WaitForChild(“PlayerGui”,5):WaitForChild(“Chat”):WaitForChild(“Frame”).ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar:ReleaseFocus(true)
end)