Im making a horror game and i want my monster to disappear during day and reappear during night.
The problem is the time goes by too fast to detect a certain time and i dont know what else to do to detect if its day or night
Script:
while game.Lighting.TimeOfDay == "6:00:00" do
local NextbotDay = game.Workspace:WaitForChild("Nextbot")
NextbotDay.Parent = game.ServerStorage
game.ReplicatedStorage.Days.Value = game.ReplicatedStorage.Days.Value + 1
end
while game.Lighting.TimeOfDay == "18:00:00" do
local NextbotNight = game.ServerStorage:WaitForChild("Nextbot")
NextbotNight.Parent = game.Workspace
end
while game.Lighting.TimeOfDay <= "6:00:00" do
local NextbotDay = game.Workspace:WaitForChild("Nextbot")
NextbotDay.Parent = game.ServerStorage
game.ReplicatedStorage.Days.Value = game.ReplicatedStorage.Days.Value + 1
end
while game.Lighting.TimeOfDay >= "18:00:00" do
local NextbotNight = game.ServerStorage:WaitForChild("Nextbot")
NextbotNight.Parent = game.Workspace
end
Use ClockTime. It is a number and will make your life easier. Also check if it within a timeframe. This is obviously extremely exaggerated if your script moves slowly. Modify to your need and be careful of while loops potentially crashing without wait times.
while game.Lighting.ClockTime == 6 and game.Lighting.ClockTime <= 7 do
local NextbotDay = game.Workspace:WaitForChild("Nextbot")
NextbotDay.Parent = game.ServerStorage
game.ReplicatedStorage.Days.Value = game.ReplicatedStorage.Days.Value + 1
end
while game.Lighting.ClockTime == 18 and game.Lighting.ClockTime <= 19 do
local NextbotNight = game.ServerStorage:WaitForChild("Nextbot")
NextbotNight.Parent = game.Workspace
end
Super scuffed and will probably cause lag? Maybe do something better than this lol
while task.wait() do
while game.Lighting.ClockTime >= 6 and game.Lighting.ClockTime <= 7 do
local NextbotDay = game.Workspace:WaitForChild("Nextbot")
NextbotDay.Parent = game.ServerStorage
game.ReplicatedStorage.Days.Value = game.ReplicatedStorage.Days.Value + 1
end
while game.Lighting.ClockTime >= 18 and game.Lighting.ClockTime <= 19 do
local NextbotNight = game.ServerStorage:WaitForChild("Nextbot")
NextbotNight.Parent = game.Workspace
end
end
I think I know why. It’s cloning every single frame, so maybe try this instead:
(By the way, it will clone nextbots constantly if you aren’t careful. Try add a way to prevent that.)
while task.wait() do
if game.Lighting.ClockTime >= 6 and game.Lighting.ClockTime <= 7 then
local NextbotDay = game.Workspace:FindFirstChild("Nextbot")
if NextbotDay then
NextbotDay.Parent = game.ServerStorage
game.ReplicatedStorage.Days.Value = game.ReplicatedStorage.Days.Value + 1
end
end
if game.Lighting.ClockTime >= 18 and game.Lighting.ClockTime <= 19 then
local NextbotNight = game.ServerStorage:WaitForChild("Nextbot")
NextbotNight.Parent = game.Workspace
end
end