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

Why isn't my door working when it's night/morning?

So I'm helping my friend make this prison game, and I'm trying to make this door transparent and not collidable at 8AM, then not transparent and collidable at 9PM. I wrote out the script, but it doesn't seem to be working. I already have a day/night cycle.

Here is the code for the transparent maker. The thing going transparent is a union.

local door = script.Parent


if game.Lighting:GetMinutesAfterMidnight() == 8*60 then
	door.Transparency = 1
	door.CanCollide = false
end
	
if game.Lighting:GetMinutesAfterMidnight() == 21*60 then
	door.Transparency = 0
	door.CanCollide = true
end

Here is my day/night cycle. (I don't think this is the issue tbh, just putting it here because it might be helpful to others!)

local interval = 0.4
local change = 0.5

while wait(interval) do
	game.Lighting.ClockTime = game.Lighting.ClockTime + change
end

Any help is appreciated!

1 answer

✓ Accepted answer

It's not working for two reasons, that I can see.

  1. You're changing ClockTime in your Time Cycle Script.

Instead of using: Lighting:GetMinutesAfterMidnight(), try using ClockTime, as well.

  1. You're not using a loop, so the script only runs the if statement once -- when the game instance starts.

It should work if you do:

local door = script.Parent

while wait() do
	if game.Lighting.ClockTime > 8 and game.Lighting.ClockTime < 21 then
	    door.Transparency = 1
	    door.CanCollide = false
	end
	
	if game.Lighting.ClockTime > 21 then
	    door.Transparency = 0
	    door.CanCollide = true
	end
end

I hope this helps! :D

1 comment

0

thank you! it worked!

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