hey everyone I want to fix a weird problem that I have in my game involving my timer system. The timer system is supposed to have a 7 minute timer and then restart and keep doing that
Whenever I load into the game the timer works but sometimes it just does not work for some reason. I have a server script that manages the actual time in a string value. Then in a local script I have the string value equal to the text label that shows on the players screen. I tested the server script and there is nothing wrong on that side because the string value is always updating. So I put a while wait() to print something in the local script and I realized that whevever the timer is not working the while wait() does not work but it does when the timer is working. I am not sure what is causing this problem, the local script not being loaded fast enough? there is some error with the script? so i would appreciate any help
local statss = game.ReplicatedStorage:WaitForChild("Value")
local val = script.Parent:WaitForChild("TextLabel")
statss:GetPropertyChangedSignal("Value"):Connect(function()
val.Text = statss.Value
end)
Also this is not the whole script its just the part the I am talking about, Please help and let me know if you need any more context or have any questions, Thx!
How often is statss getting updated? Are you swamping the engine with data every frame?
Also, why have the timer as a string setting? Using numbers might be more efficient, and they can be rounded to whatever decimal place you need.
Try printing the value in the server script and also print it in the local script to see if the timer is still running on the server but the client script is the problem.
Its just when the game loads sometimes that the script just does not work its like a 50/50 chance, it was working fine before but i dont know what happend. The reason I’m using a StringValue is because I have a 00:00 format for my timer. And it is definitely a client problem because everything serversided works perfectly fine. I also tried disabling some intensive scripts that I have that I thought could cause it to not work but it is still the same
local statsaw = game.ReplicatedStorage:WaitForChild("Value")
local minutes = 1
local Players = game:GetService("Players")
local timerval = game.ReplicatedStorage:WaitForChild("time")
timerval.Value = 1
local rep = game:GetService("ReplicatedStorage")
local mul = rep:WaitForChild("Joe")
local multi = rep:WaitForChild("multi")
local timerval = game.ReplicatedStorage:WaitForChild("time")
local signaltext = game.ReplicatedStorage:WaitForChild("Bro")
local signal = game.ReplicatedStorage:WaitForChild("signal")
local cam = game.Workspace.CurrentCamera
local spawner = game.Workspace:WaitForChild("SpawnLocation")
local folds = game.ServerStorage:WaitForChild("stage1")
local folds1 = game.ServerStorage:WaitForChild("stage2")
local folds2 = game.ServerStorage:WaitForChild("stage3")
local folds3 = game.ServerStorage:WaitForChild("stage4")
local folds4 = game.ServerStorage:WaitForChild("stage5")
local function typer(item, text, length)
for i = 1,#text,1 do
item.Text = string.sub(text,1,i)
wait(length)
end
end
local stage1
local stage2
local stage3
local stage4
local stage5
function load()
local checks = game.ServerStorage.Checkpts:Clone()
checks.Parent = game.Workspace.Stages
local stagear = folds:GetChildren()
local stage1 = stagear[math.random(1, #stagear)]:Clone()
stage1.Parent = game.Workspace.Stages
local thething = game.ServerStorage.checks:Clone()
thething.Parent = game.Workspace
local stagear1 = folds1:GetChildren()
local stagear2 = folds2:GetChildren()
local stagear3 = folds3:GetChildren()
local stagear4 = folds4:GetChildren()
local stage2 = stagear1[math.random(1, #stagear1)]:Clone()
stage2.Parent = game.Workspace.Stages
local stage3 = stagear2[math.random(1, #stagear2)]:Clone()
stage3.Parent = game.Workspace.Stages
local stage4 = stagear3[math.random(1, #stagear3)]:Clone()
stage4.Parent = game.Workspace.Stages
local stage5 = stagear4[math.random(1, #stagear4)]:Clone()
stage5.Parent = game.Workspace.Stages
end
load()
while true do
local minutes = 7
local seconds = 0
game.ReplicatedStorage:WaitForChild("MURATOR"):WaitForChild("EXTRATIME").OnServerEvent:Connect(function(player)
game.ReplicatedStorage:WaitForChild("serverSongs"):WaitForChild("horn"):Play()
for i, v in pairs(game.Players:GetChildren()) do
local textthing = v:WaitForChild("PlayerGui"):WaitForChild("ScreenGui"):WaitForChild("boughtsig")
textthing.Visible = true
typer(textthing, player.Name .. (" Bought a Minute!"), 0.05)
wait(2)
textthing.Visible = false
end
minutes += 1
end)
repeat
if seconds <= 0 then
minutes = minutes - 1
seconds = 59
else
seconds = seconds - 1
end
if seconds <= 9 then
statsaw.Value = tostring(minutes).. ":0"..tostring(seconds)
else
statsaw.Value = tostring(minutes).. ":"..tostring(seconds)
end
wait(timerval.Value)
until minutes <= 0 and seconds <= 0
if minutes <= 0 and seconds <=0 then
statsaw.Value = "0:00"
wait(1)
statsaw.Value = "Loading New Map..."
game.Workspace.Stages:ClearAllChildren()
game.Workspace.checks:Destroy()
for i, Player in pairs(game.Players:GetPlayers()) do
Player:LoadCharacter()
wait(1)
game.ReplicatedStorage:WaitForChild("fogthing"):WaitForChild("fogtrue").Value = false
for i,v in pairs(game.Lighting:GetChildren()) do
if v.Name == "fogtrue" then
v:Destroy()
end
if v.Name == "Atmosphere" then
v:Destroy()
end
end
signaltext.Value = false
multi.Value = 1
mul.Value = false
timerval.Value = 1
wait(statsaw.Value)
for _, player in ipairs(Players:GetChildren()) do
local whywhywhy = Player:WaitForChild("stage")
if whywhywhy then
whywhywhy.Value = 0
end
end
end
statsaw.Value = "Intermission 0:05"
wait(1)
statsaw.Value = "Intermission 0:04"
wait(1)
statsaw.Value = "Intermission 0:03"
wait(1)
statsaw.Value = "Intermission 0:02"
wait(1)
statsaw.Value = "Intermission 0:01"
wait(1)
load()
end
end
here you go, this is the main server script that changes the value and statsaw is the stringvalue
Okay, the script is really confusing. I suggest you use seconds in the value that is placed in ReplicatedStorage and turn theese seconds into the xx:yy format afterwards (on the client).
This would be a basic server-side timer using seconds:
local startUnix = os.time()
local maxSeconds = 7*60 --7 minutes
while task.wait() do
local currentUnix = os.time()
local currentSeconds = maxSeconds - (currentUnix - startUnix)
yourValue.Value = currentSeconds
end
the function to turn seconds into xx:yy would be:
local function addLeadingZero(s)
s = (s:len() == 1 and "0"..s) or s --if string length is 1 then string is gonna be "0"..rest of string
return s
end
local function formatSeconds(seconds)
local minutes = math.floor(seconds/60)
seconds -= minutes*60
return addLeadingZero(tostring(minutes))..":"..addLeadingZero(tostring(seconds))
end
Here is an example:
local test = 70
print("\nSeconds:"..test.." \n".."Formatted:"..formatSeconds(test))
I really appreciate the scripts and the game example you made and I was able to figure out what was causing the problem. Before the problem I remembered I was sorting though some of the scripts I had and I though maybe I might have accidently done something to mess it up so I reloaded a old save from before that and everything is working fine again so it means I must have accidently done or deleted something by accident. Thanks everyone for your help