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

How do you make Zombies spawn at night and die in the day?

Asked by 4 years ago

I have tried so hard to make Zombies spawn at night and die in the day but it is so hard, If anyone knows how to do this that would be helpful as this is key to my game.

0
I'm a noob at scripting but have you tried TimeOfDay or ClockTime under the Lighting tab combined with Humanoid damage? LimitedVxrsion 3 — 4y

1 answer

Log in to vote
0
Answered by
TrippyV 314 Donator Moderation Voter
4 years ago

Assuming that you have a functioning day/night script already made, you can use the GetPropertyChangedSignal event with the ClockTime property of Lighting to achieve what you're looking for.

Once you've connected this event, you can use a debounce to keep the function from firing in later portions of the day.

An application of this can be found below:

01local LightingService = game:GetService("Lighting")
02local TIME_DAY = 6 -- Set this to the hour you want the zombies to die
03local TIME_NIGHT = 18 -- Set this to the hour you want zombies to spawn
04local zombiesActive = false -- This is our debounce
05 
06local function ClockTimeChanged()
07    local newClockTime = LightingService.ClockTime
08 
09    if zombiesActive then
10        -- If zombies are out, lets check if the ClockTime is day.
11 
12        if (newClockTime >= TIME_DAY and newClockTime < TIME_NIGHT) then
13            zombiesActive = false
14 
15            -- PUT YOUR CODE TO DESPAWN THE ZOMBIES HERE
View all 25 lines...

The rest here is up to you. I've left comments in caps as indication of where to put your code.

If you have any questions, be sure to ask. Best of luck!

0
Wow it works thanks dude! subblox1234 9 — 4y
Ad

Answer this question