So what I am trying to do is when the TimeOfDay is 07:30:00, Saito (NPC) dies at that time, and will day everytime it hits 07:30:00. I kept changing small things from health = 0 to breakjoints lines. I am not entirely sure what I am doing wrong, but the NPC doesn't die at that time. Also this script lies within Workspace
please help! thank you!
01 | l = game:service( "Lighting" ) |
02 | r = game:service( "RunService" ) |
03 |
04 | while true do |
05 | --Time and day |
06 | if l.TimeOfDay = "07:30:00" then |
07 | game.Workspace.Saito.humanoid.Health = 0 |
08 | wait(. 2 ) |
09 | end |
10 | end |
This is an error that Output should have caught and been telling you. You use a double equal sign to do comparisons:
1 | if l.TimeOfDay = = "07:30:00" then |
Also, I suggest tabbing your code properly:
01 | l = game:service( "Lighting" ) |
02 | r = game:service( "RunService" ) |
03 |
04 | while true do |
05 | --Time and day |
06 | if l.TimeOfDay = = "07:30:00" then |
07 | game.Workspace.Saito.humanoid.Health = 0 |
08 | end |
09 | wait(. 2 ) --The loop will crash if the condition is false and only waits inside the loop. |
10 | end |
I also suggest looking into the GetMinutesAfterMidnight
method, which is a bit more useful than TimeOfDay