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

(Solved) Lights are only working while running, not working while playing in studio?

I have just come up with this script to turn on lights in a building I have made.

while true do
	wait(.2)
function lights()
	if game:GetService("Lighting"):GetMinutesAfterMidnight() <= 6*60 then
		script.Parent.BrickColor = BrickColor.new("Cork")
		script.Parent.Material = "Neon"
		script.Parent.Reflectance = 0
		script.Parent.Transparency = 0.2
	elseif game:GetService("Lighting"):GetMinutesAfterMidnight() >= 7*60 then
		script.Parent.BrickColor = BrickColor.new ("Bright bluish green")
		script.parent.Material = "Glass"
		script.Parent.Reflectance = 0.3
		script.Parent.Transparency = 0
	end
end
lights()
end

I have tried switching game:Getservice("Lighting"):GetMinutesAfterMidnight() to game.Lighting.ClockTime, but neither is working. It still works while running, but refuses to work after I spawn in my character. I'm very new to scripting so I apologize if there is an obvious fix.

I have also tried this in both normal and local scripts. The normal script at least works when running the game, the local script didn't work at all. Still the same issue.

while true do
	wait(.2)
function lights()
	local lighting = game:GetService("Lighting"):GetMinutesAfterMidnight()
	if  lighting <= 6*60 then
		script.Parent.BrickColor = BrickColor.new("Cork")
		script.Parent.Material = "Neon"
		script.Parent.Reflectance = 0
		script.Parent.Transparency = 0.2
	elseif lighting >= 7*60 then
		script.Parent.BrickColor = BrickColor.new ("Bright bluish green")
		script.parent.Material = "Glass"
		script.Parent.Reflectance = 0.3
		script.Parent.Transparency = 0
	end
end
lights()
end

5 comments

0

Are you getting any errors? Are there any other scripts affecting the lights? What kind of script are your running that program from (localscript or script)?

0

I am not getting any errors and that is the only script in the game at the moment. I'm running it on a script.

0

I just tried running it on a local script and now it doesn't work at all.

0

is it something with your setting. like graphics arent high enough to see. if it is this go to file settings rending and turn up the quality.

0

No, I have it maxed at level 21

1 answer

I have just figured it out, when I changed the time while playing I was only changing it client side, not server side. I added Khol's admin for a sec, because I figured that using the :time command would change the time server side. Sure enough, even my first script worked. Thank you to everyone who responded! :)

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