generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: May seem like a needy request but, script help:

Previous Thread :: Next Thread 
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 11:18 AM
I'm using a TimeOfDay changing script, which also modifies the Fog as well, I am not too brainy with using math to do all sorts of tweening functions and such, but it works in Studio, as soon as you enter in game, it is incrementing but then setting back to the default DayAlpha (time in a division of 1, i.e 0.5 is 12, 1 is 24). I found that out by looping a print on the client to show it in the console, and it kept saying: 12:00:00 and then quickly jumping to the incremented time, so it is working, but it is jumping back to 12:00:00 each time, I have tried changing the DayAlpha variable, yet nothing seems to be working. I will leave the code below, if anybody is kind enough to help me, that would be appreciated.

-- This is the most realistic TOD script yet, 24 minutes = 1 day. 1 minute = 1 hour. Sun and moon move realisticly...

lighting = game:service("Lighting")

DayAmbient = Color3.new(99/255, 97/255, 85/255) --for 0-255, make sure to divide by 255 e.g. 128/255
DayBrightness = 1
DayOutdoorAmbient = Color3.new(127/255, 121/255, 110/255)
DayShadowColor = Color3.new(.59,.59,.59)
DayFogColor = Color3.new(.59,.59,.59)
DayFogEnd = 4000
DayFogStart = 0

NightAmbient = Color3.new(0,0,0)
NightBrightness = .3
NightOutdoorAmbient = Color3.new(0.1,0.1,0.1)
NightShadowColor = Color3.new(.59,.59,.59)
NightFogColor = Color3.new(2/255, 2/255, 2/255)
NightFogEnd = 1000
NightFogStart = 0

TotalDayLength = 24 --minutes

SummerDayLength = 50 --arbitrary units, gets divided by total
SummerTransitionLength = 20 --actually half of the time since it appears twice
SummerNightLength = 30

WinterDayLength = 30
WinterTransitionLength = 20
WinterNightLength = 50


--do not touch below plz
SecondsPerYear = 31556900
--formula = "(tick()-(math.floor(tick()/31556900)*31556900))/31556900"
YearAlpha = 0
DayAlpha = 0.5
calc = function() YearAlpha = (tick()-(math.floor(tick()/31556900)*31556900))/31556900 end
calc()
function calc2(alpha,be,en)local a = 0 if be ~= en then a = (-math.cos(math.pi*alpha*2)/2+0.5)*(en-be)+be else a = be end return a end
function calc3(alpha,be,en)local a = 0 if be ~= en then a = (-math.cos(math.pi*alpha)/2+0.5)*(en-be)+be else a = be end return a end
function calc4(alpha,be,en)local r = 0 local g = 0 local b = 0 if be.r ~= en.r then r = (-math.cos(math.pi*alpha)/2+0.5)*(en.r-be.r)+be.r
else r = be.r end if be.g ~= en.g then g = (-math.cos(math.pi*alpha)/2+0.5)*(en.g-be.g)+be.g else g = be.g end if be.b ~= en.b then
b = (-math.cos(math.pi*alpha)/2+0.5)*(en.b-be.b)+be.b else b = be.b end return Color3.new(r,g,b)end
function setl(input)lighting:SetMinutesAfterMidnight(input*1440)end
sl = math.abs(SummerDayLength)+math.abs(SummerTransitionLength)+math.abs(SummerNightLength)
wl = math.abs(WinterDayLength)+math.abs(WinterTransitionLength)+math.abs(WinterNightLength)
function upl(a)
lighting.Ambient = calc4(a,NightAmbient,DayAmbient)
lighting.Brightness = calc3(a,NightBrightness,DayBrightness)
lighting.OutdoorAmbient = calc4(a,NightOutdoorAmbient,DayOutdoorAmbient)
lighting.ShadowColor = calc4(a,NightShadowColor,DayShadowColor)
lighting.FogColor = calc4(a,NightFogColor,DayFogColor)
lighting.FogEnd = calc3(a,NightFogEnd,DayFogEnd)
lighting.FogStart = calc3(a,NightFogStart,DayFogStart)
end
MorningLength = 5/24
TwilightLength = 2/24
DayLength = 10/24
TwilightLength = 2/24
NightLength = 5/24
while true do
calc()
local TR = calc2(YearAlpha,wl,sl)
local DL = calc2(YearAlpha,math.abs(WinterDayLength),math.abs(SummerDayLength))/TR
local TL = calc2(YearAlpha,math.abs(WinterTransitionLength),math.abs(SummerTransitionLength))/TR
local NL = calc2(YearAlpha,math.abs(WinterNightLength),math.abs(SummerNightLength))/TR
repeat
wait(0.05)
DayAlpha = DayAlpha+0.05/(TotalDayLength*60)
pr############### #if##ayAlpha <= NL/2 then
local al = (DayAlpha)/NL*2
setl(al*MorningLength)
print("first "..al)
upl(0)
elseif DayAlpha <= (NL/2+TL/2)then
local al = (DayAlpha-NL/2)/TL*2
setl(al*TwilightLength+MorningLength)
print("second "..al)
upl(al)
elseif DayAlpha <= (NL/2+TL/2+DL) then
local al = (DayAlpha-NL/2-TL/2)/DL
setl(al*DayLength+TwilightLength+MorningLength)
print("third "..al)
upl(1)
elseif DayAlpha <= (NL/2+TL+DL) then
local al = (DayAlpha-NL/2-TL/2-DL)/TL*2
setl(al*TwilightLength+DayLength+TwilightLength+MorningLength)
print("fourth "..al)
upl(1-al)
else
local al = (DayAlpha-NL/2-TL-DL)/NL*2
setl(al*NightLength+TwilightLength+DayLength+TwilightLength+MorningLength)
print("fifth "..al)
upl(0)
end
until DayAlpha >= 1
DayAlpha = 0
print("It's a new day!")
end


Report Abuse
HalfPinky456 is not online. HalfPinky456
Joined: 10 Apr 2011
Total Posts: 6236
17 Dec 2016 11:21 AM
try to narrow down the problem, posting huge blocks of code is usually confusing and has less chance of getting help
Report Abuse
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 11:22 AM
The paragraph which I provided before the huge block of code explains my issue, it works in Studio as it should, but then as soon as you try it on a server, it will increment the TimeOfDay as it should, but then it jumps back to the default time which is set as the DayAlpha value, meaning that it never actually increases the time properly.


Report Abuse
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 11:23 AM
I've honestly tried everything, but I don't have any more will power to continue, so I brought my problem here hoping that somebody else has experienced it with the same script and can fix it.


Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
17 Dec 2016 11:25 AM
debug debug and more debugging

lots of prints and experimenting.


Report Abuse
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 11:27 AM
I have done that, I have looked practically EVERYWHERE. I don't see where a problem could lie, if anybody could just quickly scan through it and see.. I would appreciate that :[


Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
17 Dec 2016 11:32 AM
thats awful

you can simply change how fast a day is like this:

local Lighting = game.Lighting
local Day = 6 --AM
local Night = 8 --PM
local Speed = 24 --How many minutes a day is

UpdateLights = function(Time)
if Time >= Day*60 and Time < (Night+12)*60 then
--Day
elseif Time > (Night+12)*60 or (Time > 0 and Time < Day*60) then
--Night
end
end

Lighting.Changed:connect(function()
local Time = Lighting:GetMinutesAfterMidnight()
UpdateLights(Time)
end)

while wait() do
Lighting:SetMinutesAfterMidnight(Lighting:GetMinutesAfterMidnight()+(1440/(60*Speed)/30))
end


Report Abuse
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 11:33 AM
The main thing that was required was the fog and the ambient changing, but thanks :>


Report Abuse
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 11:43 AM
Bump.


Report Abuse
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 11:53 AM
Still requiring help for this, cannot find a thing.


Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
17 Dec 2016 11:57 AM
try to narrow down the problem, posting huge blocks of code is usually confusing and has less chance of getting help [2]
Report Abuse
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 11:59 AM
I'm afraid that didn't help, what so ever, if you had been reading my replies.


Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
17 Dec 2016 12:03 PM
you aren't getting help because you have posted too much code (most of which is probably irrelevant), and so if you want help you will have to narrow down the code

i'm trying to get you to get help for your problem, but from a helper's perspective, it's extremely difficult and time-consuming to try to understand every single line of that script
Report Abuse
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 12:04 PM
alright, well here is where I THINK the problem lies, because it is where it sets the TimeOfDay and then reverts back to default, for some reason.

function setl(input)lighting:SetMinutesAfterMidnight(input*1440)end
sl = math.abs(SummerDayLength)+math.abs(SummerTransitionLength)+math.abs(SummerNightLength)
wl = math.abs(WinterDayLength)+math.abs(WinterTransitionLength)+math.abs(WinterNightLength)
function upl(a)
lighting.Ambient = calc4(a,NightAmbient,DayAmbient)
lighting.Brightness = calc3(a,NightBrightness,DayBrightness)
lighting.OutdoorAmbient = calc4(a,NightOutdoorAmbient,DayOutdoorAmbient)
lighting.ShadowColor = calc4(a,NightShadowColor,DayShadowColor)
lighting.FogColor = calc4(a,NightFogColor,DayFogColor)
lighting.FogEnd = calc3(a,NightFogEnd,DayFogEnd)
lighting.FogStart = calc3(a,NightFogStart,DayFogStart)
end
MorningLength = 5/24
TwilightLength = 2/24
DayLength = 10/24
TwilightLength = 2/24
NightLength = 5/24
while true do
calc()
local TR = calc2(YearAlpha,wl,sl)
local DL = calc2(YearAlpha,math.abs(WinterDayLength),math.abs(SummerDayLength))/TR
local TL = calc2(YearAlpha,math.abs(WinterTransitionLength),math.abs(SummerTransitionLength))/TR
local NL = calc2(YearAlpha,math.abs(WinterNightLength),math.abs(SummerNightLength))/TR
repeat
wait(0.05)
DayAlpha = DayAlpha+0.05/(TotalDayLength*60)
--################# #if##ayAlpha <= NL/2 then
local al = (DayAlpha)/NL*2
setl(al*MorningLength)
--print("first "..al)
upl(0)
elseif DayAlpha <= (NL/2+TL/2)then
local al = (DayAlpha-NL/2)/TL*2
setl(al*TwilightLength+MorningLength)
--print("second "..al)
upl(al)
elseif DayAlpha <= (NL/2+TL/2+DL) then
local al = (DayAlpha-NL/2-TL/2)/DL
setl(al*DayLength+TwilightLength+MorningLength)
--print("third "..al)
upl(1)
elseif DayAlpha <= (NL/2+TL+DL) then
local al = (DayAlpha-NL/2-TL/2-DL)/TL*2
setl(al*TwilightLength+DayLength+TwilightLength+MorningLength)
--print("fourth "..al)
upl(1-al)
else
local al = (DayAlpha-NL/2-TL-DL)/NL*2
setl(al*NightLength+TwilightLength+DayLength+TwilightLength+MorningLength)
--print("fifth "..al)
upl(0)
end
until DayAlpha >= 1
DayAlpha = 0
print("It's a new day!")
end

Hope that is more helpful for you. @Aggressive


Report Abuse
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 12:04 PM
#########################################################
Report Abuse
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 12:05 PM
ROBLOX doesn't seem to like that line, but it is just checking if DayAlpha is less than or equal to NL divided by 2.


Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
17 Dec 2016 12:08 PM
so the issue is that the time never changes? or it changes for a bit and then goes back to midnight? or noon?
Report Abuse
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 12:09 PM
It changes yes, but then INSTANTLY pops back to midnight / noon, the default value you set with the variable 'DayAlpha'.

It is set between 0 and 1, and is basically divided by 24.


Report Abuse
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 12:10 PM
For example: 0.5 would be noon, 1, midnight, and 0 midnight.


Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
17 Dec 2016 12:11 PM
print(DayAlpha) before and after this line

DayAlpha = DayAlpha+0.05/(TotalDayLength*60)


and tell me what prints
Report Abuse
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 12:16 PM
As soon as the script started:

Before: 0.83348588582524
After: 0.83349283026968

DayAlpha starts as math.random() as well.


Report Abuse
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 12:25 PM
Got anything?..


Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
17 Dec 2016 12:32 PM
how do the next couple of prints look?
Report Abuse
Collect1ve is not online. Collect1ve
Joined: 24 Dec 2008
Total Posts: 772
17 Dec 2016 12:33 PM
Same as the after print but then continues incrementing onwards, there was no obvious changes with it, and it didn't jump back to the random number either.


Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
17 Dec 2016 12:36 PM
perhaps try adding brackets on all of these

setl(al*(DayLength+TwilightLength+MorningLength))

each if statement gets progressively longer
maybe add brackets around all of the addition sequences
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image