Time function doesn't work?

So basically, when it’s 18:00 I want it to do a function, pretty simple, no errors but doesn’t work.

game.Players.PlayerAdded:Connect(function(player)
	function paycheck()
		print("PAYCHECK APE")
		--rest of my code
		--rest of my code
	end
end)

if game.Lighting.ClockTime == 18 then
	paycheck()
end

at the part “–rest of my code” is just copying gui and placing in playergui,

Nothing too complicated but tryna get it fixed.

1 Like

Would it work if the ‘if’ statement was in a :GetPropertyChangedSignal("ClockTime") connection for lighting?

Right now I believe [if nothing else wraps around the ‘if’ statement] that it checks only once when the server starts and returns false.

1 Like

Let me try it out sir.

I’ll leave a comment if it worked or not

1 Like

Didn’t work, no errors sadly.
Any other solutions you maybe got?

1 Like

This is more of a backup, but could the GUI be handled client sided and triggered via a remote event?
That way you could run something like

local Lighting = game:GetService("Lighting")
Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if Lighting.ClockTime == 18 then
		-- fire a remote event with the correct arguments
	end
end)
1 Like

it’s a serverscript, I’m jus tryna copy paste a gui to the playergui for all, so is using serverscript fine?

1 Like

Yeah, it should be.
If you use that event tree with the executed code inside of it, does it run properly or not?

[the pains of debugging… gah]

1 Like

GetPropertyChangedSignal would be a right move here… U probably didnt from the code right

1 Like

Doesn’t work sadly, no errors again..

1 Like

The fact that it doesnt throw any errors makes this more weird than it normally would be.

Dumb question, if you put a print("|| PlayerUI || Code ran without error ||") inside of the if statement does it print when the time hits 18?

1 Like

Nop.. still doesn’t print anything or function.

1 Like

Give me a moment ~
I’m going to run this in a test place to try to force it to push some sort of error, or output at all.

1 Like

Alright, if i won’t respond after is because i’m in a online class rn so it might take a while.

1 Like

This is from the hub:
“Note, this property does not correspond with the actual time of day and will not change during the game unless it has been changed by a script.”

Maybe TimeOfDay would be the right move

2 Likes

That makes way more sense,
do what @nuttela_for1me suggested and use ‘TimeOfDay’
Use string.sub() or something to get the hour, then index that with ‘18’.

1 Like

:GetPropertyChangedSignal() was my solution to that. It fires whenever a property updates.

2 Likes

Sum like this??


local Lighting = game:GetService("Lighting")
Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function(player)
	if Lighting.TimeOfDay == "18:00:00" then
		print("|| PlayerUI || Code ran without error ||")
	end
end)

If yes then my answer: didn’t work

1 Like

Hmm I am not sure, bc I didnt really work with that, but he cun probably check for “18:00” as a whole string

2 Likes

I already tried it here,

I’m not sure what TimeOfDay uses, I don’t know if it’s a string or not.
Try using print(string.sub(Lighting.TimeOfDay, 1, 2)) and see if it returns the first two numbers.

1 Like