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

Help with TimeOfDay script?

Asked by
Xl5Xl5 65
8 years ago

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!

l = game:service("Lighting") 
r = game:service("RunService")

while true do 
--Time and day
if l.TimeOfDay = "07:30:00" then
game.Workspace.Saito.humanoid.Health = 0
wait(.2)
end 
end

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

This is an error that Output should have caught and been telling you. You use a double equal sign to do comparisons:

if l.TimeOfDay == "07:30:00" then

Also, I suggest tabbing your code properly:

l = game:service("Lighting") 
r = game:service("RunService")

while true do
    --Time and day
    if l.TimeOfDay == "07:30:00" then
        game.Workspace.Saito.humanoid.Health = 0
    end 
    wait(.2) --The loop will crash if the condition is false and only waits inside the loop.
end

I also suggest looking into the GetMinutesAfterMidnight method, which is a bit more useful than TimeOfDay

Ad

Answer this question