Hello,
So, I created a script which would tween the terrain color depending on if its day or night, but it doesn’t work properly. First off, the grass doesn’t change once it reaches 6 hours. Second off, once it becomes night, it turns green for a split second and tweens to be blue, which is weird. I think this is a visual glitch, since it tweens from green to blue once it becomes night. Any help will be appreciated. The code is as follows:
local terrain = game.Workspace.Terrain
local value = "1"
local daynight = true
print("gotpastcode3")
local colorValue = Instance.new("Color3Value")
colorValue.Value = terrain:GetMaterialColor("Grass")
colorValue.Parent = script.Parent
print("gotpastcode2")
colorValue:GetPropertyChangedSignal("Value"):connect(function()
terrain:SetMaterialColor("Grass", colorValue.Value)
end)
print("gotpastcode1")
terrain:SetMaterialColor("Grass", Color3.fromRGB(91, 122, 380))
local tweenInfo = TweenInfo.new(30, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local tweenInfo2 = TweenInfo.new(30, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local Night = game:GetService("TweenService"):Create(colorValue, tweenInfo, {Value = Color3.fromRGB(91, 122, 380 )})
local Day = game:GetService("TweenService"):Create(colorValue, tweenInfo2, {Value = Color3.fromRGB(110, 148, 70)})
print("got past code")
while true do
Time = game.Lighting.TimeOfDay
TimeOfDay = Time
hour = TimeOfDay:split(':')
hours = tonumber(hour[1])
if hours >= 17 and hours <= 20 then
print("17-20 hours")
if daynight == false then
Night:Play()
print("Tweened")
daynight = true
wait(0.1)
end
end
if hours >= 6 and hours <= 9 then
print("6-9 hours")
if daynight == true then
Day:Play()
print("Tweened")
daynight = false
wait(0.1)
end
end
print("Looped!")
print(hours)
wait(0.1)
end
EDIT 1- The loop works, since it prints “looped”, which means that the tweening is not working