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

Why isn't the ambient/outdoor ambient changing with the time while my script is running?

Asked by 6 years ago

This script is relatively simple-- the script gets the clocktime, multiplies it by 10, and sets that as the ambient in the game. It does essentially the same thing with the outdoor ambient, except it subtracts clocktime * 10 by 10.

clockTime = game.Lighting.ClockTime

while true do
game.Lighting.Ambient = Color3.new((clockTime * 10)/255,(clockTime * 10)/255,(clockTime * 10)/255) 
game.Lighting.OutdoorAmbient = Color3.new(((clockTime * 10) - 10)/255,((clockTime * 10) - 10)/255,((clockTime * 10) - 10)/255)
wait(1)
end

It works upon running the game- set it to any time, run the script and it works. However, I also have a simple copy/paste day-to-night cycle script running as well:

minutesAfterMidnight = 0
while true do
    minutesAfterMidnight = minutesAfterMidnight + 60
    game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
    wait(60)
end

and the ambient doesn't update with the time as it changes. Any suggestions on how to make this work? Thanks.

1 answer

Log in to vote
0
Answered by 6 years ago

This is because it is only defined once. For example, if you did

local name = game.Workspace.Part.Name
workspace.Part.Name = 'something'
print(name)

it would not print "something". To fix this, just define it in the while loop. Also, try merging these two scripts together, as they do small tasks to get similar things done.

local minutesAfterMidnight = 0
while true do
    minutesAfterMidnight = minutesAfterMidnight + 60
    game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
     local clockTime = game.Lighting.ClockTime

    game.Lighting.Ambient = Color3.fromRGB((clockTime * 10)/255,(clockTime * 10),(clockTime * 10)) 
    game.Lighting.OutdoorAmbient = Color3.new(((clockTime * 10) - 10),((clockTime * 10) - 10)/255,((clockTime * 10) - 10))

    wait(60)
end

Also, you should go see this. I combined the two while loops so the ambient changing changes almost instantly from the lighting changing, instead if one script needed to load significantly longer than the other script.

Hope this helps!

0
Thanks! secondrowcellist 0 — 6y
0
Accept my answer if this helped! hiimgoodpack 2009 — 6y
0
Wait- how do I do that again? I haven't used this website in 6 months and I keep forgetting everytime I come back :/ secondrowcellist 0 — 6y
0
Should be next to the report button. Don't click the report button, click the button that says accept answer near it. hiimgoodpack 2009 — 6y
View all comments (4 more)
0
Nope, even turned off my ad blocker and it isn't there. That's weird, I've never had that happen before. secondrowcellist 0 — 6y
0
Also another question, sorry that I didn't mention it in my earlier post but it just came to mind. When the clock time reaches 15, I want it to start subtracting the time instead of adding. Is there any way to tell the script to do that after the time reaches 15? secondrowcellist 0 — 6y
0
Why not turn all the addition symbols to subtraction? Makes sense, right? hiimgoodpack 2009 — 6y
0
What I meant is like, how I would tell the script to start doing that right at 15. I'd assume something like, if game.Lighting.ClockTime >= "15" then, but it errors. secondrowcellist 0 — 6y
Ad

Answer this question