Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script has no error but isn't running at all, nothing even shows in Script Performance??

Following the Day/Night cycle tutorial, I decided to separate the statements that operate the Lamps from turning on and off depending on the day and the statements that cycles through Day and Night.

When I did that, the script doesn't work at all but it shows no error, there is nothing inside Script Performance either so I know it's not running.

The script is inside a part called "Lightpart" along with another child called "PointLight" which is a PointLight. The parent of Lightpart is a Model.

Lamp Operator... (Code that doesn't work)

if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then
	wait(1)
	script.Parent.Material = Enum.Material.Neon
	wait(1)
	script.Parent.PointLight.Enabled = true
end
if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then
	wait(1)
	script.Parent.Material = Enum.Material.Plastic
	wait(1)
	script.Parent.PointLight.Enabled = false
end

Day/Night cycle... (Code that works)

lightPart = game.Workspace.Model.Lightpart
minutesafterMidnight = 0
while true do
	minutesafterMidnight = minutesafterMidnight + 5
	game.Lighting:SetMinutesAfterMidnight(minutesafterMidnight)
	wait(.1)
end

As for why I chose to separate those two codes, it's because I notice that the codes do not run independently from each other so whenever I add in a debounce in the Lamp Operator, the Day/Night cycle stops for that rebound to.

1 comment

0

Is the first code on a loop, and why is it missing an end? Are the two code snippets in the same script, if so, while loops will stop the rest of the code from running because a script, unless used with certain methods, will essentially only do one thing at a time.

1 answer

✓ Accepted answer

1st code does not work because it is no looped. If you launch game with the time game.Lighting:GetMinutesAfterMidnight() == 18 * 60 it will do stuff, since server is started and time is not game.Lighting:GetMinutesAfterMidnight() == 18 * 60 it won't work. You should add the first code into while wait() do loop :

while wait() do
  if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then
      wait(1)
      script.Parent.Material = Enum.Material.Neon
      wait(1)
      script.Parent.PointLight.Enabled = true
  if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then
      wait(1)
      script.Parent.Material = Enum.Material.Plastic
      wait(1)
      script.Parent.PointLight.Enabled = false
  end
end

2 comments

0

What is the wait() in while wait() do suppose to be if it has no value in it?

0

It's the shortest time a wait function can wait.

This discussion is preserved as it was. New answers, comments, and votes are closed.