This is my first time working with DisplaySystemMessage() but I seemingly can’t get it to post anything in chat. Might anyone be able to tell me why based on the code and hierarchy?
task.wait(2)
local Lighting = game:GetService("Lighting")
local TextChatService = game:GetService("TextChatService")
local tag = "[Coalopolis]:"
function sunsetWarning()
TextChatService.TextChannels.RBXSystem:DisplaySystemMessage(tag .. "The sun is starting to set!")
end
function sunriseWarning()
TextChatService.TextChannels.RBXSystem:DisplaySystemMessage(tag .. "The sun is starting to rise!")
end
if Lighting.ClockTime == 6 then
sunriseWarning()
end
The issue is most likely the if Lighting.ClockTime == 6 line. It may not be exactly 6 if the time is being animated.
Try this instead!
local lastTime = Lighting.ClockTime
RunService.Heartbeat:Connect(function()
local time = Lighting.ClockTime
if time >= 6 and lastTime < 6 then
sunriseWarning()
end
lastTime = time
end)
Your code was only checking the ClockTime once, meaning if it wasn’t passed 6 then it would never print, even if the time did eventually pass 6. My code checks every heartbeat (60 times a second) to see if the ClockTime has just passed 6!