Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is causing this script to be so sluggish?

Asked by
Suamy 68
7 years ago

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)

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. davness 376 — 7y
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. Suamy 68 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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
Ad

Answer this question