Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is causing this script to be so sluggish?

This is a timer that counts from 300 to 0. I intended to have a wait() of 1, but when I used that, each second was around 3 seconds (I compared it to Google timers).

What is with this delay?

workspace.TimerOn.Changed:connect(function()
	for timer = 300, 0, -1 do
		if workspace.TimerOn.Value == true then
			script.Parent.Text = tostring(timer)
			wait(0.25) -- I changed the wait to 0.25 to correct the time
		end
	end
end)

script.Parent.Changed:connect(function()	
	if game.Workspace.TimerOn.Value == true and script.Parent.Text == "0" then
		-- fire an event when timer is at 0
	end
end)

2 comments

0

Check for vírus (infections) in your game. Their scripts delay the execution of the ones you really need; They do hurt wait() times aswell. I already worked on a game with 3000+ infections, and the performance impact was huge, not to say the weight of the files.

0

I checked Script Performance, and nothing out of my knowledge was hogging CPU space, I don't think there are infections in my game.

1 answer

✓ Accepted answer

Try this custom wait(), which utilizes tick() - it may be more accurate:

local function custom_wait(seconds)

	local current = tick()
	local goal = seconds+current
	while tick()<=goal do
		wait(.00005)
	
	end
	return
end

This discussion is preserved as it was. New answers, comments, and votes are closed.