for some reason script on serverscriptservice didnt detect every player’s playergui
ive tried putting the local playergui to top, and using localp still didnt work
local Players = game:GetService("Players")
local function checkTimer()
for _, player in pairs(Players:GetPlayers()) do
local playerGui = player.PlayerGui.main.dayNIghTextlb
if playerGui.Text == "night" then
game.Lighting.ClockTime = 19
end
end
end
checkTimer()
this script suppose to be change the clocktime to 20 when every playergui’s textlabel night
local function checkTimer()
for _, player in ipairs(Players:GetPlayers()) do -- ipairs instead of pairs
local playerGui = player.PlayerGui.main.dayNIghTextlb
if playerGui.Text == "night" then
game.Lighting.ClockTime = 19
end
end
end
ipairs will return the list of the player and index.
try it
checkTimer() is running before the players are even added. you could use a while loop to check every second. (this definitely isn’t the best solution, but it works.)
while true do
checkTimer()
task.wait(1)
end
you’ll also want to use Instance:FindFirstChild, since the gui might not exist when the player is immediately added.
The code description:
-Get all Label
-Check “night”
-Executed
You only ran that once at the start of the server
At that moment none of the labels texted “night” yet You must add an event or something to trigger the function or do some repetitive tasks so it can check every second or something.