NPC
Non Player Character
Non Player Character
local Chat = game:GetService("Chat")
local npc = script.Parent
local characterParts = npc.CharacterParts
local head = characterParts.Head
local clickDetector = npc.ClickDetector
-- Stores a list of dialogue to say
local dialogueArray = {"Hi!", "Today's a great day!", "Good bye!"}
local dialogueIndex = 1
-- Shows a new dialogue whenever the NPC is clicked
local function speak()
local dialogue = dialogueArray[dialogueIndex]
Chat:Chat(head, dialogue)
-- If the increment is at the end of the array, set it back to the start
if dialogueIndex == #dialogueArray then
dialogueIndex = 1
-- Else, just add 1 to the increment to keep moving up in the array
else
dialogueIndex = dialogueIndex + 1
end
end
clickDetector.MouseClick:Connect(speak)