I can't find objects in a clone

I have a message template. When I clone it, the actual instance clones but not the children.

Script

local chatMessage = storage.ChatMessage:Clone()

chatMessage.Author.Name.Badge.Visible = true

Log

Players.intergraviation.PlayerGui.CustomChat.ClientChatScript:23: attempt to index nil with 'Visible' 

Explorer (ChatMessage is the thing I am cloning)

image

By the way, Archivable is on.

You need to give the chatMessage a parent.

ex: chatMessage.Parent = game.StarterUI

I tried that but it didn’t seem to fix it. Same log appears.

Script

local chatMessage = storage.ChatMessage:Clone()

chatMessage.Parent = chatBox

chatMessage.Author.Name.Badge.Visible = true

Are there any other scripts interfering with this?

Well, there is a server script that clones the main gui to the StarterGui. There is a localscript inside of that main gui which is the script we are talking about here.

Hmm idk then. I tried doing this in studio with similar stuff and it worked.

1 Like

Did you reference “storage” correctly?

2 Likes

image

Variables

local storage = script.Parent.Container.Storage
local chatBox = script.Parent.Container.ChatBox
local inputBox = script.Parent.Container.InputBox

There does not seem to be any errors in the script. Are there any error outputs?

image

Heres the actual entire script:

local storage = script.Parent.Container.Storage
local chatBox = script.Parent.Container.ChatBox
local inputBox = script.Parent.Container.InputBox

replicatedStorage.ShowMessage.OnClientEvent:Connect(function(msgArgs)
	local chatMessage = storage.ChatMessage:Clone()
	chatMessage.Parent = chatBox
	
	if msgArgs.messageSettings.showBadges == true then
		if msgArgs.player.MembershipType == Enum.MembershipType.Premium then
			chatMessage.Author.Name.Badge.Visible = true
		end
	else
		chatMessage.Author.Name.Badge.Visible = false
	end
	if msgArgs.player.DisplayName == "" then
		chatMessage.Author.Name.Name.Text = msgArgs.player.Name
	else
		chatMessage.Author.Name.Name.Text = msgArgs.player.DisplayName
	end
	chatMessage.Author.Profile.Image = "https://www.roblox.com/headshot-thumbnail/image?userId=" .. msgArgs.player.UserId .. "&width=420&height=420&format=png"
	if msgArgs.messageSettings.showTime == true then
		chatMessage.Author.Name.Time.Text = os.date("%I:%M %p")
	else
		chatMessage.Author.Name.Time.Visible = false
	end
	chatMessage.Message.Text.Text = msgArgs.messageText
	
	chatMessage.Visible = true
end)

Ok so I tried cloning it into workspace and it actually does have all of it’s children, so the script just can’t see it for some reason
image

Could you try printing “msgArgs” right after the ShowMessage event?

Here it is

  02:02:19.882   â–Ľ  {
                    ["messageSettings"] =  â–Ľ  {
                       ["showBadges"] = true,
                       ["showTime"] = true
                    },
                    ["messageText"] = "v",
                    ["player"] = intergravitation
                 }  -  Client - ClientChatScript:17
  02:02:19.883 

Is “msgArgs” the text the player typed in the text box?

SO the way this system works is these steps:

  1. Client sends the message they want, just a normal string
  2. Server filters the message
  3. Server then makes a new table called “msgArgs” and has a few contents like:
    • messageSettings = the settings the creator of the game chooses
    • messageText = the message the player sends
    • player = the player who sent it
  4. Sends this to all the clients
  5. The client reads the table and clones the message box into the chat box
  6. Client changes stuff in the message box like the message/author text, etc

I don’t really know if this would be a good way to even make a chat system though.

Hm, Understood. I looked through the scripts, and I do not find any errors. Sorry, but I do not know what is causing this issue. Try printing something in the scripts. You will eventually find the source of error. I would be happy to help you out on Roblox Studio, however, if you are not comfortable with it, someone else may be able to help you.

1 Like

Ok, thanks for helping! I will look into this since this is the most important part of chat, seeing the actual messages. Maybe I will try a different way.

Do you have any ideas?

Alright, I apologize for not being able to assist you. I saw your other post in the “Cool Creations” category about the chat that looks very high quality like Discord. Scripting this original chat system is possible, and there is definitely a method to achieve this.

1 Like

Hm, I have never thought of making my own chat system.

  1. Client sends the message they want, just a normal string
  2. Server filters the message
  3. Server then makes a new table called “msgArgs” and has a few contents like:
  • messageSettings = the settings the creator of the game chooses
  • messageText = the message the player sends
  • player = the player who sent it
  1. Sends this to all the clients
  2. The client reads the table and clones the message box into the chat box
  3. Client changes stuff in the message box like the message/author text, etc

You sent the above earlier, and this system should work as long as the scripts are correct and functional.

1 Like

As I mentioned above, try adding adding a print function in your scripts.
I have done this method before, and it is pretty helpful.

1 Like