Making Players Chat

Hello Cookie Tech,

I’m trying to create a command that makes a chain of chat bubbles appear out of the top of them when they run a command.

So far, I’m not exactly sure how to do this, as I need to check if the player runs a command, and if they do, a chain of messages comes out from on top of them.

I can’t seem to find any resources that can help me with this, and I’m very new to scripting.

Do note: I’m not asking for a full script, I’m asking for resources that could help explain how to do this.

What’s the use case for this?

I’m making an automated training system, so a Trainer runs -train and all the information will automatically come out of them. This is for users who don’t have discord so won’t be able to access a guide for training, and just makes the process easier.

Solution:


I see, you can use the chatService .

If this solves your issue, mark it as solution!

Example:


Input:

local ChatService = game:GetService("Chat")

local part = Instance.new("Part")

part.Anchored = true

part.Parent = workspace

wait(3)

ChatService:Chat(part, "Blame John!", "Red")

Output:
image

Documentation


Docs can be found here.

Thanks so much! I’m not going to mark this as the solution quite yet in case I run into any other issues. Thanks Cookie!

Docs are quite complicated, do you know which page would specifically help me check if a player chatted a specific message?

Hello, this might help. But if you want to look for a more detailed tutorial try this tutorial. I hope this helps!

local PlayerService = game:GetService("Players")

PlayerService.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg == "COMMAND" then
			--Script Here
		end
	end)
end)

(Also change line 5 to your command)

Great, if @Max.Mobey has helped you remember to mark as soloution

1 Like

Would this work with a ScreenGui? (Changing the “part” to a Frame for example)

No, why would you want the screengui to chat? Couldn’t you display that type of data with a textlabel?

Huh? That’s not what I meant at all. I think I misunderstood the script. I thought you had to touch the part in order to make the message come out of the player, but now I see the message is coming out of the part. How do I make the player chat the messages?

Make the head of the player the part:

local part = Instance.new("Part")

Okay, thanks. (20 char)

So it would be local part = Instance.new("plr.Head") right? (combining max_mobey’s script)

Wait, never mind that. So I edited the script and it turned out like this.

local PlayerService = game:GetService("Players")
local ChatService = game:GetService("Chat")


PlayerService.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg == "-train" then
			local Character = plr.Character
			local part = Character.Head
			part.Anchored = true

			part.Parent = workspace

			wait(3)

			ChatService:Chat(part, "Test", "Black")
		end
	end)
end)

But when saying -train in the chat, the player gets killed and I receive the error: “Unable to cast string” in the output.

No, you don’t want to make this, there’s no point in trying to create this unless you don’t understand fundamentals, I would reccommend learning how to code before learning how to create things.

Also you don’t want to anchor the part of set the parent to workspace, nor do you want to wait 3 seconds.

Well, you should learn how to code properly or at least learn how to understand core functions of code, otherwise it will just be us completely solving the code, that get’s you nowhere when trying to learn code.

Alright then. I suppose I’ll mark this as the solution, thanks.

1 Like

Remember, learning is key, it will make you a better scripter! :hugs: