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

How do I make a npc move when I say "Hi" in chat?

Example: when i type "hi" in the chat, the NPC will start walking to me.

3 answers

Scripting Helpers is not a request site! (But I’ll give you the part that detects if you say “hi” in chat)


local PlayersService = game:GetService("Players")
local StringToDetect = "hi"

PlayersService.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if string.find(string.lower(Message), string.lower(StringToDetect)) then
			if Player.Character then
				-- code
			end
		end
	end)
end)

local str = "Hi"
local npc_character = PATH.TO.YOUR.NPC

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAppearanceLoaded:Wait()
    local char = player.Character
    player.Chatted:Connect(function(msg)

        if string.find(
                string.lower(msg),
                string.lower(str)
            ) then

            local npc_hum =
                npc_character:FindFirstChildOfClass("Humanoid")

            if not npc_hum then
                return
            end

            npc_hum:MoveTo(char:GetPrimaryPartCFrame().Position)
        end

    end)
end)

haven't tested

1 comment

0

local npc_character = game.Workspace.The Npc’s name . NoSpacesInTheName

Scripting Helpers is not a request site it is a website where you ask the community to help debug errors with your code and help other people debug errors with their code.

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