NPC that responds to a specified message

Hello there!

I just made a script that allows a rig to respond to a specified message that you send via the chatbox! You can use it too!

All you have to do is add a rig to your workspace and insert a script inside of it. Place the following script that is shown down below:

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

Feel free to change the respond message and the message that the rig will reply to! I hope this script has helped you a lot and if it did, feel free to leave feedback down below! I would really appreicate it!

Happy coding!

10 Likes

Wow! This simple recourse would help new developers a lot. Maybe make it a tutorial, as it is easy.

2 Likes
game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
if msg == "Hi!" and (script.Parent.HumanoidRootPart.Position - player.Character:FindFirstChildOfClass("Humanoid").RootPart.Position).Magnitude < 10 then
			wait(1)
			game:GetService("Chat"):Chat(script.Parent.Head, "Hey there " .. player.name, Enum.ChatColor.Blue)
		end
	end)
end)

I think this is better, so the NPC only responds if you’re near it.

2 Likes

Here’s a more modifiable version of the code


game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
replies={
["Hi"]="Hey there "..player.name.."."
}	
	if replies[msg]~=nil then
			wait(1)
			game:GetService("Chat"):Chat(script.Parent.Head, replies[msg], Enum.ChatColor.Blue)
		end
	end)

Also this a Classic chatbot script that does this more dynamically you can return the message and do the
game:GetService(“Chat”):Chat(script.Parent.Head, result, Enum.ChatColor.Blue)

Eliza Chatbot Ported to Luau [Open-Source] - Resources / Community Resources - Developer Forum | Roblox

Pretty cool! :sunglasses: :+1: Good job!!!