[RESOLVED] Tween starts at 0 each time played

Main Script:

-- Services
local rs = game:GetService("RunService")
local status = rs:IsRunning()
local light = game:GetService("Lighting")
local ts = game:GetService("TweenService")


-- Variables & Module scripts
local details = require(script.Parent.Details)
local cur = script.currentTime
local reality = script.aspectReality


-- Inital setting of the ClockTime.
game.Lighting.ClockTime = tonumber(cur.Value)
game.Lighting.Atmosphere.Density = 0.3

-- tween info
local ti = TweenInfo.new(6)

-- Main Module
while status and task.wait(12) do -- 10 minutes (600)
	if game.Lighting.ClockTime == 0 then
		game.Lighting.ClockTime = 0.001
		cur.Value = 0.001
	end
	game.Lighting.ClockTime = details.time(tonumber(cur.Value),tonumber(reality.Value))
	local goal = {}
	goal.Density = details.weather()
	game.Lighting.Atmosphere.Density = ts:Create(game.Lighting.Atmosphere,ti,goal):Play()
	cur.Value = tostring(game.Lighting.ClockTime)
	wait(7)
	print("World Update, debugging...\n\nTime:\n"..game.Lighting.ClockTime.."\n\nWeather:\n"..game.Lighting.Atmosphere.Density)
end

Module Script:

handler.weather = function()
	local typeid = script.Parent.Main.weatherType
	local values={
		"foggy",
		"veryfoggy",
		"toofoggy",
		"normal",
		"clear"
	}
	local maintype = values[math.random(1, #values)]
	print(maintype)
	if maintype == "foggy" then
		return 0.4
	elseif maintype == "veryfoggy" then
		return 0.5
	elseif maintype == "toofoggy" then
		return 0.7
	elseif maintype == "normal" then
		return 0.3
	elseif maintype == "clear" then
		return 0.1
	end
end


I would like if the tween added or subtracted itself from the value it was until it reaches the chosen value.

Did you manually change the value to 0.3 after you hit run? It’s possible that you had only changed it on the client, so the server wasn’t aware of the change.

No the value is set to 0.3 on join (via server script), even still it wouldn’t go from 0 its default is 0.375 or something.

Odd. Just to make sure, can you add a print statement just before the tween that outputs the current value of density?

“Normal” - Should be 0.3
image
“Clear” - Should be 0.1
image

It reaches the value successfully but it starts from 0 each time it runs. (Which I don’t want)
(Ignore time, the whole time thing works well)

-- Services
local rs = game:GetService("RunService")
local status = rs:IsRunning()
local light = game:GetService("Lighting")
local ts = game:GetService("TweenService")


-- Variables & Module scripts
local details = require(script.Parent.Details)
local cur = script.currentTime
local reality = script.aspectReality


-- Inital setting of the ClockTime.
game.Lighting.ClockTime = tonumber(cur.Value)
game.Lighting.Atmosphere.Density = 0.3

-- tween info
local ti = TweenInfo.new(6)

-- Main Module
while status and task.wait(12) do -- 10 minutes (600)
	if game.Lighting.ClockTime == 0 then
		game.Lighting.ClockTime = 0.001
		cur.Value = 0.001
	end
	game.Lighting.ClockTime = details.time(tonumber(cur.Value),tonumber(reality.Value))
	local goal = {}
	goal.Density = details.weather()
	game.Lighting.Atmosphere.Density = ts:Create(game.Lighting.Atmosphere,ti,goal):Play()
	cur.Value = tostring(game.Lighting.ClockTime)
	wait(7)
	print("World Update, debugging...\n\nTime:\n"..game.Lighting.ClockTime.."\n\nWeather:\n"..game.Lighting.Atmosphere.Density)
end

Definitely odd. I can’t find any errors in the code that could be causing this issue. I gotta go get some sleep so I’ll have to leave this question to someone else. Sorry about being unable to better assist.

1 Like

Hey! If anyone needs extra details I can provide them.

The code should go from the original value down or up to reach the value returned by the module script.

Still very much so unresolved.

Might as well test using more debug things. If you put a print statement just BEFORE the tween that outputs the density, what it say (as opposed to the other one which was 7 seconds after the tween)

Updated my initial post to contain the entire main script.
There are also values that change within the scripts:
image

aspect reality remains 1, the current time is set to: 24.001
and weather type is set to “normal”
although that doesn’t matter at this stage.
and doesn’t affect anything in the script

Hello, try to do something like this

1 Like

Thank you for your help but one of my friends highlighted the core issue:
"

game.Lighting.Atmosphere.Density = ts:Create(game.Lighting.Atmosphere,ti,goal):Play()

this line
is not necessary

ts:Create(game.Lighting.Atmosphere,ti,goal):Play()

"

1 Like