So I am trying to make NPCs say different things depending on the time of day. When I tried running this, it did not work. I got the idea from a time of day script and a chat script I found online, and I felt like doing a script like this would give more life to the NPCs.
wait (2)
local ChatService = game:GetService("Chat")
-- You can also add wait() function before this line if you want.
local part = script.Parent.Head
DayLines = {"Good Afternoon.","Where do you want to eat?","I heard there is a ghost haunting the school, creepy right?"}
NightLines = {"We should be getting home.","I am sleepy...","zzzz"}
MorningLines = {"Good Morning","What did you have for breakfast?","See you later!"}
EveningLines = {"Night is soon, we should be going home.","It's getting dark...","See you tomorrow!"}
while wait(2) do
if game.Lighting.ClockTime > 6 and game.Lighting.ClockTime < 10 then
local Chat = ChatService:Chat(part, [math.random(1,#MorningLines)], "White")
wait(20)
elseif game.Lighting.ClockTime > 10 and game.Lighting.ClockTime < 14 then
local Chat = ChatService:Chat(part, [math.random(1,#DayLines)], "White")
wait(20)
elseif game.Lighting.ClockTime > 20 or game.Lighting.ClockTime < 6 then
local Chat = ChatService:Chat(part, [math.random(1,#NightLines)], "White")
wait(20)
elseif game.Lighting.ClockTime > 14 and game.Lighting.ClockTime < 20 then
local Chat = ChatService:Chat(part, [math.random(1,#EveningLines)], "White")
wait(20)
end
end
Any ideas on how to make it work?

2 comments
Thanks
No problem.