NPC not saying my name

I created a script that would make an NPC reply to a specific message that I send via the chatbox. However, when I added the built-in function “player” into the message, it responded to me saying “Hello there (player)”. Here is what the script looks like:

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == "Hi!" then
			game:GetService("Chat"):Chat(script.Parent.Head, "Hey there (player)", Enum.ChatColor.Blue)
		end
	end)
end)

What do I need to fix?

2 Likes

I think u need to do this

	player.Chatted:Connect(function(msg)
		if msg == "Hi!" then
			game:GetService("Chat"):Chat(script.Parent.Head, "Hey there " .. player.name, Enum.ChatColor.Blue)
		end
	end)
end)

first idk about the () inside “”
Because “” means text
to add text u need to do . .
then add somethind
second problem u did player not player.name

I might have problems bc i didnt check

1 Like

@Encrypted_Youtube already gave you the answer but here’s a good resource on string manipulation:

It worked! Thank you so much for you support!

1 Like

@Encrypted_Youtube how can I add a message after he says my name?

1 Like

By doing …“Stuff here” after the name thingy

Btw can u add me on discord my discord is encdata

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.