Wait(1) Actually waiting about 5-10 seconds

This was caused by server lag from me not debouncing a die script.

Game link

Note that a lot of this code is quite badly structured / hard to read, that’s pretty much all from the bug fixes I’ve tried to do, first thinking it was RemoteEvent firing lag, then thinking it was lag from the animate() function, which animates the text on, and a load of other stuff.

Okay so, I’ve already done a lot of testing on this, but essentially I have a for loop which times the space taken to answer the question.

local timeAmount = 17
if answerLength > 50 then
timeAmount = math.floor(((answerLength / 50)*10)/8 + 15)
end
local shown = false
for i = 1, timeAmount do
local timeLeft = timeAmount - i
spawn(function()
_G.animate(timer, timeLeft)
end)
game.Workspace.ServerValues.TimeLeft.Value = timeLeft
if timeLeft < 10 and shown == false then
shown = true
pcall(function()spawn(function()
showAnswer:FireAllClients()
end)end)
end
wait(1)
end

The global animate function changes the text on the BillboardGui, and the animation for it is fired to take place clientside. The TimeLeft value in workspace is for clientside usage, and the timeAmount is usually about 15 seconds, but the actual period of waiting ends up being about 1-2 minutes; this is obviously really annoying for gameplay, and the server script stats and server memory show little signs of overloading or lag, at the time of the timer running, it’s definitely the main consumer of memory in the game.

If anyone could give me some tips or point out a really stupid mistake I’ve made, that would be great! :smiley:

[details=“Server memory and script stats screenshots”]
Bear in mind this data may be from a server that wasn’t having issues, I’m not sure.
[/details]

Solved.

1 Like

Please don’t just say solved, others may have this issue. What did you do to solve it?

9 Likes

He said what he did to solve it, although not too obvious to see it.

1 Like

This is what I did, I will always put how I solve things if it’s useful to others, but this doesn’t seem to be one of those situations where it would be, hence the short one line sentence.

I didn’t see it in your OP, my mistake.

1 Like

No worries! :smiley:

2 Likes

I’d reccomend putting game.Workspace.ServerValues into ReplicatedStorage or ServerStorage instead (what they’re intended for) because if someone makes an account called ServerValues then your game is going to error.

Untrue. When indexing, Roblox only returns the object added first.

(And also, I just registered an account called ServerValues, set it to a random password with no email, and logged out, so now nobody can do that even theoretically)

Also ‘ServerStorage’ is server sided, so it wouldn’t work with my intended use. It really doesn’t matter if it’s in workspace or replicatedstorage, I just prefer to keep it in workspace.