Hi everyone! I've working on a NPC that greet you with a GUI (Text label).
I want to make a text label that contain "Good morning" / "Good afternoon" / "Good evening".
Here is the local script:
local player = game.Players.LocalPlayer game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function() if game.Lighting.ClockTime >= 5 and game.Lighting.ClockTime >= 11 then script.Parent.Text = "Good morning, " .. player.Name .."! Welcome to the hotel! What can I do for you?" elseif game.Lighting.ClockTime >= 12 and game.Lighting.ClockTime >= 19 then script.Parent.Text = "Good afternoon, " .. player.Name .."! Welcome to the hotel! What can I do for you?" elseif game.Lighting.ClockTime >= 20 and game.Lighting.ClockTime >= 4 then script.Parent.Text = "Good evening, " .. player.Name .."! Welcome to the hotel! What can I do for you?" end end)
But the NPC don't detect which hour it is...someone can say me which is the problem or what I should do to make it work?
Thanks!
I think the problem is that you're checking if ClockTime
is greater than and greater than, when it should be greater than and LESS than, something like this:
local player = game.Players.LocalPlayer game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function() if game.Lighting.ClockTime >= 5 and game.Lighting.ClockTime < 12 then script.Parent.Text = "Good morning, " .. player.Name .."! Welcome to the hotel! What can I do for you?" elseif game.Lighting.ClockTime >= 12 and game.Lighting.ClockTime < 20 then script.Parent.Text = "Good afternoon, " .. player.Name .."! Welcome to the hotel! What can I do for you?" elseif game.Lighting.ClockTime >= 20 and game.Lighting.ClockTime < 5 then script.Parent.Text = "Good evening, " .. player.Name .."! Welcome to the hotel! What can I do for you?" end end)
Also, although ClockTime
is ok to use, I would advice you to use TimeOfDay
if you want to be more precise:
if game.Lighting.TimeOfDay >= "6:00:00" and game.Lighting.TimeOfDay < "12:00:00" then --Use strings, otherwise it will error --Your Code