Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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
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)? akatak_prime 48 — 4y
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. RenicuIous 0 — 4y
0
I just tried running it on a local script and now it doesn't work at all. RenicuIous 0 — 4y
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. McCreatorYT 0 — 4y
0
No, I have it maxed at level 21 RenicuIous 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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! :)

Ad

Answer this question