How to make script that NPC will spawn at night? (or specific time)

so first, the NPC will at ServerStorage but if the TimeofDay is 20 the NPC will move to Workspace and spawning

(pls help im beginner at coding)

1 Like

This is how to run code at the time of day you asked for. If you want it to despawn, feel free to add logic following the same.

local Lighting = game:GetService("Lighting")

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
    local timeOfDay = Lighting.ClockTime

    if timeOfDay == 20 then
        -- spawn
    end
end)

Note that the above is untested but it should theoretically work.

3 Likes

thank you i will try to script it

1 Like

If it ends up working for you just please make sure to mark it as a solution so people don’t end up coming here continuing to try to help! :slight_smile:

1 Like

uhh it doesnt work, does this script work? cuz im new

local Lighting = game:GetService("Lighting")
local ServerStorage = game:GetService("ServerStorage")
local spawnZ = game.Workspace.Spawn1z

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	local timeOfDay = Lighting.ClockTime

	if timeOfDay == 12 then
		local Noob = ServerStorage.NPC['NPC Noob']:Clone()
		Noob.Parent = game.Workspace.NPC
		Noob.HumanoidRootPart.CFrame = CFrame.new(spawnZ.Position + Vector3.new(0,5,0))
	end
end)
1 Like

never mind its work thank you for your script @IllustriousGreed

i just edited some codes then it working

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.