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

How do I tween a part's color based on time of day?

Asked by 2 years ago
Edited 2 years ago

Hey all! I have a simple tween script to change the color of a part depending on the time of day. There are no errors or anything that comes up wrong when the script plays ingame, but the color of the part does not change whatsoever. I'm unsure if its because the color3.fromRGB is incorrect, or if there is another way I should make the tween. Here is the code:

local part = script.Parent
local Info = TweenInfo.new(1)
local Tween = game:GetService("TweenService"):Create(part,Info,{Color = Color3.fromRGB(0, 0, 0)})--Nighttime
local Info2 = TweenInfo.new(1)
local Tween2 = game:GetService("TweenService"):Create(part,Info2,{Color = Color3.fromRGB(159, 161, 172)})--Daytime

if game.Lighting:GetMinutesAfterMidnight() > 17.2 * 60 then --Checks Nighttime
    Tween:Play()
end

if game.Lighting:GetMinutesAfterMidnight() > 7 * 60 then --Checks Daytime
    Tween2:Play()
end

Unsure of what I should change as the script seems to be okay otherwise! Thank you very much!

Edit : Part is a union if that changes anything! The union has UsePartColor on! Thanks! I actually also changed and added a print function to check when it is daytime or nighttime to show me whether or not it works. It shows that it prints out the Daytime check, but not Nighttime. Here is the new script :

local part = script.Parent
local Info = TweenInfo.new(1)
local Tween = game:GetService("TweenService"):Create(part,Info,{Color = Color3.fromRGB(0, 0, 0)})--Nighttime
local Info2 = TweenInfo.new(1)
local Tween2 = game:GetService("TweenService"):Create(part,Info2,{Color = Color3.fromRGB(159, 161, 172)})--Daytime

if game.Lighting:GetMinutesAfterMidnight() > 17.2 * 60 then --Checks Nighttime
    print("BrickNightCheck")
    Tween:Play()
else
if game.Lighting:GetMinutesAfterMidnight() > 7 * 60 then --Checks Daytime
    print("BrickDayCheck")
    Tween2:Play()
    end
end

1 answer

Log in to vote
0
Answered by 2 years ago

Hey all! I actually just ended up looking harder and found a solution that works! I found this users' post and just edited the script a little bit! Here is the post!

https://devforum.roblox.com/t/brick-color-changing-script-not-working/355581

And here is the script!

local part = script.Parent
local Info = TweenInfo.new(1)
local Tween = game:GetService("TweenService"):Create(part,Info,{Color = Color3.fromRGB(0, 0, 0)})--Nighttime
local Info2 = TweenInfo.new(1)
local Tween2 = game:GetService("TweenService"):Create(part,Info2,{Color = Color3.fromRGB(159, 161, 172)})--Daytime

while true do
    wait(.1)
    local timeoday = game.Lighting.ClockTime 
    if timeoday > 17.6 or timeoday < 6.4 then
        Tween:Play() --Nighttime
    else
        Tween2:Play() --Daytime
    end
end

Might edit it a bit more down the line, but for now and for anyone looking for a script like this, it works for me! Thanks to those who read!

Ad

Answer this question