Is it able to make a function call when something is being printed in output

ello fellow developers,

i am currently trying to make a textlabel refresh everytime the TimeOfTheDay has changed in the lighting
however i tried using the “changed” function it didnt work so i changed it into while true do but it didnt refresh all the time it just refreshed once and then stopped.

LocalScript Wich Should change its text when TimeOfDay Has changed
local TimeLabel = script.Parent
local timeofday = game.Lighting.TimeOfDay

while true do
	TimeLabel.Text = timeofday
end
ServerScript wich changes the time its sum free model i found
l = game:service("Lighting") 
while true do 
	print("Loading...")
	wait(0.890)
l:SetMinutesAfterMidnight(l:GetMinutesAfterMidnight()+1)
end

I Would specify myself as lua beginner due to i can modify scripts etc but when i have to write one myself i often struggle with the way on how i should call a function because i dont know the ways how to call one

1 Like

The reason the while true do loop doesn’t work is because there is no yield. U should use :GetPropertyChangedSignal() to get a event that fires when a specific property gets changed.

1 Like

so would it look like this ?

local TimeLabel = script.Parent
local timeofday = game.Lighting.TimeOfDay

timeofday:GetPropertyChangedSignal(function()
	TimeLabel.Text = timeofday
end

:GetPropertyChangedSignal() returns a RBXScriptSignal, to add a Event Listener to ot use :Connect()

Example

game:GetService("Lighting"):GetPropertyChangedSignal("TimeOfDay"):Connect(function() -- Get Lighting service then use : GetPropertyChangedSignal("TimeOfDay") to get a event that fires when TimeOfDay changes.
 -- Do stuff here
end)
1 Like

bro it still dosent work for me ??? :C

https://gyazo.com/5fd3f8c50f97e79fdcc786715c7dbb6f

local TimeLabel = script.Parent
local timeofday = game.Lighting.TimeOfDay

game:GetService("Lighting"):GetPropertyChangedSignal("TimeOfDay"):Connect(function()
 	TimeLabel.Text = timeofday
end)

thats a local script i use btw

Any errors in Output? Try adding Prints too. Also, u need to change the TimeOfDay variable, the variable stays the same

what you mean change the variable ? im forgein i understand lua text often better then normal english lol

print("He means that the variable should be updated, change the variable inside the function and not outside.")
1 Like

do oyu mean instead

TimeLabel.Text = timeofday

i should do

TimeLabel.Text = game.Lighting.TimeOfDay.Text

It wasn’t updating because the variable is constant and you aren’t updating it. Here is what it would be:

local TimeLabel = script.Parent

game:GetService("Lighting"):GetPropertyChangedSignal("TimeOfDay"):Connect(function()
 	TimeLabel.Text = game.Lighting.TimeOfDay
end)

oh thanks good to know that atleast i though the variable updates itself