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

Custom Chat Help! Not a valid member?

Screenshots: (Studio https://ibb.co/bE4MXk) (Client https://ibb.co/mCEidQ)

I got help from ROBLOX Wiki for part of the script, but I started adding in more stuff, but I think it somehow broke the script. On my ROBLOX Client's Developer Console, it says:

NameLabel is not a valid member of Frame Script 'Players.Jxemes.PlayerGui.ChatScreen.ChatScript, Line 42 - upvalue addMessage Script 'Players.Jxemes.PlayerGui.ChatScreen.ChatScript, Line 64

I tried adding a WaitForChild("ChatTags") instead of just leading to it directly and simply. But it didn't work. I thought it would be related to ChatTags, because that's the most recent one I added, and I did some moving around in the script, but left it obvious that it, "should" work. I'll leave the script below.

-- I made a unique version of a VIP gamepass. Instead of "VIP" It will be "Elite". "Elite Gamepass" "Elite Member" (Just ignore that, my idea. I called it first :DD)

local ContextActionService = game:GetService("ContextActionService")

local MAX_MESSAGES = 10
local MESSAGE_HEIGHT = 15

local player = game.Players.LocalPlayer
local messages = {}
local chatMessageEvent = game.ReplicatedStorage.ChatMessage

local chatScreen = script.Parent
local ChatTags = chatScreen:WaitForChild("ChatTags")
local chatFrame = chatScreen.ChatFrame
local chatInput = chatFrame.ChatInput
local messageFrame = chatFrame.MessageFrame
local messageTemplate = messageFrame.Message:Clone()
messageFrame.Message:Destroy()

local function addMessage(sender, message)
	if #messages >= MAX_MESSAGES then
		table.remove(messages, #messages):Destroy()
	end
	
	for i = 1, #messages do
		local y = (MAX_MESSAGES - i - 1) * MESSAGE_HEIGHT
		messages[i].Position = UDim2.new(0, 0, 0, y)
	end	

	local newMessage = messageTemplate:Clone()
	local NameLabel = newMessage.NameLabel
	local Content = newMessage.Content
	
	if player.Name == "Zingoro" then
		newMessage.NameLabel.TextColor3 = chatScreen.ChatTags.Zingoro.Value
		newMessage.Content.TextColor3 = chatScreen.ChatTags.Zingoro.Value
		newMessage.NameLabel = "[CREATOR] " ..player.Name.. ""
		
	elseif player.Name == "Jxemes" then
		newMessage.NameLabel.TextColor3 = chatScreen.ChatTags.Jxemes.Value
		newMessage.Content.TextColor3 = chatScreen.ChatTags.Jxemes.Value
		newMessage.NameLabel = "[DEVELOPER] " ..player.Name.. ""
		
	elseif player.Name == "LinkMe" then
		newMessage.NameLabel.TextColor3 = chatScreen.ChatTags.LinkMe.Value
		newMessage.Content.TextColor3 = chatScreen.ChatTags.LinkMe.Value
		newMessage.NameLabel = "[DEVELOPER] " ..player.Name.. ""
		
	elseif game:GetService("GamePassService"):PlayerHasPass(player, 0)then
		newMessage.NameLabel.TextColor3 = chatScreen.ChatTags.Elite.Value
		newMessage.Content.TextColor3 = chatScreen.ChatTags.Elite.Value
		newMessage.NameLabel = "[ELITE] " ..player.Name.. ""
		
	else
	newMessage.NameLabel.Text = sender.Name .. ": "
	newMessage.Content.Text = message
	newMessage.Parent = messageFrame
	newMessage.Position = UDim2.new(0, 0, 0, (MAX_MESSAGES - 1) * MESSAGE_HEIGHT)
	table.insert(messages, 1, newMessage)
end
end
local function onFocusLost(enterPressed, inputObject)
	if enterPressed then
		addMessage(player, chatInput.Text)
		chatMessageEvent:FireServer(chatInput.Text)
		chatInput.Text = "Click Here or Press ''/'' to say something!"
	end
end

local function onSlashPressed(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.End then
		chatInput:CaptureFocus()
	end
end

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
chatMessageEvent.OnClientEvent:connect(addMessage)
chatInput.FocusLost:connect(onFocusLost)
ContextActionService:BindAction("Chatting", onSlashPressed, false, Enum.KeyCode.Slash)

Anyone got any ideas to help me fix this?

1 answer

I believe the error is that you are doing

NameLabel = "[DEVELOPER]" blah blah blah 

and not

NameLabel.Text = "[DEVELOPER]" blah blah blah

If this helped, please accept this as the answer so people know it has been solved and if they are having the same problem they can also have the answer. If you have any more questions feel free to ask.

Here's the full code.

-- I made a unique version of a VIP gamepass. Instead of "VIP" It will be "Elite". "Elite Gamepass" "Elite Member" (Just ignore that, my idea. I called it first :DD)

local ContextActionService = game:GetService("ContextActionService")

local MAX_MESSAGES = 10
local MESSAGE_HEIGHT = 15

local player = game.Players.LocalPlayer
local messages = {}
local chatMessageEvent = game.ReplicatedStorage.ChatMessage

local chatScreen = script.Parent
local ChatTags = chatScreen:WaitForChild("ChatTags")
local chatFrame = chatScreen.ChatFrame
local chatInput = chatFrame.ChatInput
local messageFrame = chatFrame.MessageFrame
local messageTemplate = messageFrame.Message:Clone()
messageFrame.Message:Destroy()

local function addMessage(sender, message)
    if #messages >= MAX_MESSAGES then
        table.remove(messages, #messages):Destroy()
    end

    for i = 1, #messages do
        local y = (MAX_MESSAGES - i - 1) * MESSAGE_HEIGHT
        messages[i].Position = UDim2.new(0, 0, 0, y)
    end 

    local newMessage = messageTemplate:Clone()
    local NameLabel = newMessage.NameLabel
    local Content = newMessage.Content

    if player.Name == "Zingoro" then
        newMessage.NameLabel.TextColor3 = chatScreen.ChatTags.Zingoro.Value
        newMessage.Content.TextColor3 = chatScreen.ChatTags.Zingoro.Value
        newMessage.NameLabel.Text = "[CREATOR] " ..player.Name.. ""

    elseif player.Name == "Jxemes" then
        newMessage.NameLabel.TextColor3 = chatScreen.ChatTags.Jxemes.Value
        newMessage.Content.TextColor3 = chatScreen.ChatTags.Jxemes.Value
        newMessage.NameLabel.Text = "[DEVELOPER] " ..player.Name.. ""

    elseif player.Name == "LinkMe" then
        newMessage.NameLabel.TextColor3 = chatScreen.ChatTags.LinkMe.Value
        newMessage.Content.TextColor3 = chatScreen.ChatTags.LinkMe.Value
        newMessage.NameLabel.Text = "[DEVELOPER] " ..player.Name.. ""

    elseif game:GetService("GamePassService"):PlayerHasPass(player, 0)then
        newMessage.NameLabel.TextColor3 = chatScreen.ChatTags.Elite.Value
        newMessage.Content.TextColor3 = chatScreen.ChatTags.Elite.Value
        newMessage.NameLabel.Text = "[ELITE] " ..player.Name.. ""

    else
    newMessage.NameLabel.Text = sender.Name .. ": "
    newMessage.Content.Text = message
    newMessage.Parent = messageFrame
    newMessage.Position = UDim2.new(0, 0, 0, (MAX_MESSAGES - 1) * MESSAGE_HEIGHT)
    table.insert(messages, 1, newMessage)
end
end
local function onFocusLost(enterPressed, inputObject)
    if enterPressed then
        addMessage(player, chatInput.Text)
        chatMessageEvent:FireServer(chatInput.Text)
        chatInput.Text = "Click Here or Press ''/'' to say something!"
    end
end

local function onSlashPressed(actionName, inputState, inputObject)
    if inputState == Enum.UserInputState.End then
        chatInput:CaptureFocus()
    end
end

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
chatMessageEvent.OnClientEvent:connect(addMessage)
chatInput.FocusLost:connect(onFocusLost)
ContextActionService:BindAction("Chatting", onSlashPressed, false, Enum.KeyCode.Slash)

3 comments

0

Well, i tried it, But it won't show what I said, any way to fix it?

0

I just realized

0

It looks like in your code, you're only setting the name in the if and elseif statements. You aren'te setting Content.Text

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