Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make NPCs say something different depending on time of day?

Asked by 4 years ago
Edited 4 years ago

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?

1 answer

Log in to vote
0
Answered by 4 years ago

The problem is you aren't actually getting any info from the tables, instead you are just choosing a random number between 1 and #Lines. It should be for example:

local Chat = ChatService:Chat(part, MorningLines[math.random(1,#MorningLines)], "White")

so,

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, MorningLines[math.random(1,#MorningLines)], "White")
        wait(20)
    elseif game.Lighting.ClockTime > 10 and game.Lighting.ClockTime < 14 then
        local Chat = ChatService:Chat(part, DayLines[math.random(1,#DayLines)], "White")
        wait(20)
    elseif game.Lighting.ClockTime > 20 or game.Lighting.ClockTime < 6 then
        local Chat = ChatService:Chat(part, NightLines[math.random(1,#NightLines)], "White")
        wait(20)
        elseif game.Lighting.ClockTime > 14 and game.Lighting.ClockTime < 20 then
        local Chat = ChatService:Chat(part, EveningLines[math.random(1,#EveningLines)], "White")
        wait(20)
        end
    end

Should do.

0
Thanks WarUmbmon12 2 — 4y
0
No problem. WizyTheNinja 834 — 4y
Ad

Answer this question