Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to use TimeOfDay to change a NumberValue...? [SOLVED]

What I'm trying to achieve with this script is:

There's a NumberValue within each player in the game, I want the script to set it to 0 after TimeOfDay changes to 6:00:00 or more, but I only want it to change once that time has passed, and then leave it.

local players = game.Players:GetPlayers()
local currentTime = game.Lighting:GetMinutesAfterMidnight()/60
 
game.Lighting.Changed:connect(function(prop)
if prop == "TimeOfDay" then
	if currentTime >= 6 and currentTime < 20 then
		for i = 1, #players do
		players[i].Tiredv.Value = 0
		print'changed'
		end		end 
		
	else
	print'not time' 
	 

	end
end)


After trying what @alphawolvess said,

I have this:

local players = game.Players:GetPlayers()
local currentTime = game.Lighting:GetMinutesAfterMidnight()/60
 
game.Lighting.Changed:connect(function()
	if game.Lighting.TimeOfDay == "06:00:00" then
		for i = 1, #players do
		players[i].Tiredv.Value = 0
		print'changed'
		end	
		
	else
	print'not time' 
	 

	end
end)



And that still isn't working, I've tried 'game.Lighting.LightingChanged:connect(function()', and that also isn't working. Any ideas why this script might not be working as the script tells it to?

It prints 'not time', but when time == 06:00:00 it doesn't run the if statement... Hmm ;/

2 comments

0

TimeOfDay is used in string: game.Lighting.TimeOfDay = "6:00:00". Also, try to use LightingChanged instead of Changed.

0

I think this would best be done via LocalScript unless you've got FilteringEnabled on. Do you have it on? If you don't, I'll whip up a script that should work.

1 answer

TimeOfDay is returned to you as a string. Change it and check it like this:

if game.Lighting.TimeOfDay:sub(1,2)>=6 then
     print("Heck yea")
end

Or:

game.Lighting.TimeOfDay="06:00:00" --This'll change it to 6 o' clock. You shouldn't check what it is this way.

Try what I did in the first script, and format it to fit into your script correctly. I think you understand how to do it from here, if not leave a comment and i'll see what I can do. Hope I helped :P

9 comments

0

USE 'TONUMBER'

0

What's that do?

0

Just saying, :sub(1,2) still returns a string. You need to convert that to a number

0

Still, the script is only printing "not time", nothing changed

0

It converts it to a number automatically when you use it with a numbervalue i thought?

0

Update ur question with what u did with my suggestion, and let me see it. I'll see what you or I did incorrectly...

0

I have it solved now, :D

0

Awesome. What'd u do to fix it?

0

I've also posted to the Scripting forums on ROBLOX, @JimmyChance, did this: http://www.roblox.com/Forum/ShowPost.aspx?PostID=159708580#159712608

This discussion is preserved as it was. New answers, comments, and votes are closed.