The loop (attached below) does not seem to run at all. The script has responded to everything outside the loop and below it, but nothing inside it. I’ve come to the conclusion that the loop is not running and hence is the problem. I can’t figure out why.
P.S. I had it working perfectly fine prior to this. The script is a ModuleScript btw and there is no error I see.
Thanks!
You shouldn’t write code other than functions and variables inside a ModuleScript. For actually executing the code, put this into a server script instead. Also, task.spawn exists instead of coroutine.resume coroutine.create.
local s, err = pcall(function()
require(script.Parent.Systems.ServerLocation)()
require(script.Parent.Systems.ServerUptime)()
end)
if not s then warn(err) end
serveruptime script
return function()
print("Name | Loading uptime")
if not workspace:FindFirstChild("name1") then
workspace:WaitForChild("name")
if not workspace:FindFirstChild("Name1"):FindFirstChild("Server_Statistics") then
workspace.name1:WaitForChild("Server_Statistics")
end
end
local su_folder = Instance.new("Folder", workspace.name1.Server_Statistics)
su_folder.Name = "Server_Uptime"
local su_value_full = Instance.new("StringValue", su_folder)
su_value_full.Name = "Full"
local uptime = {
seconds = 1;
minutes = 0;
hours = 0;
}
print("Name | Loaded uptime (1/3)")
local function update_time()
local prefixs = {
seconds = "";
minutes = "";
hours = "";
}
if string.len(tostring(uptime.seconds)) == 1 then
prefixs.seconds = "0"
end
if string.len(tostring(uptime.minutes)) == 1 then
prefixs.minutes = "0"
end
if string.len(tostring(uptime.hours)) == 1 then
prefixs.hours = "0"
end
su_value_full.Value = prefixs.hours.. tostring(uptime.hours).. ":".. prefixs.minutes.. tostring(uptime.minutes).. ":".. prefixs.seconds.. tostring(uptime.seconds)
print("updated")
end
print("Name | Loaded uptime (2/3)")
coroutine.resume(coroutine.create(function()
while wait(1) do
print(6)
if uptime.seconds < 59 then
uptime.seconds += 1
update_time()
else
if uptime.minutes < 59 then
uptime.seconds = 0
uptime.minutes += 1
update_time()
else
uptime.seconds = 0
uptime.minutes = 0
uptime.hours += 1
end
end
end
end))
print("Name | Loaded uptime (3/3)")
end
You must always return a value at the end of a module script. If the pic you posted in the first post is the complete code, you forgot to add a return at the end.
Also, I had a similar problem in the past, where my module scripts would randomly stop working, even if they worked just fine a moment before. I believe it might be a bug on ROBLOX part, and I fixed it by simply copypasting the code onto a brand new module script, while deleting the previous one.