New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Variable is not being set, How come?

Asked by
Benbebop 118
12 days ago
Edited 12 days ago
local Stats = game:GetService("ContentProvider")
local Divisor = 0

local TotalInstances = game:GetChildren()

while true do
    if Divisor <= Stats.RequestQueueSize then
        local Divisor = Stats.RequestQueueSize
    end
    wait()
    script.Parent.Text = 100*(1-(Stats.RequestQueueSize/Divisor)) .. "% |" .. Divisor .. "|" .. Stats.RequestQueueSize
end

Divisor stays at 0, why is that? I need it to be the highest number ContentProvider.RequestQueueSize reaches.

1 answer

Log in to vote
1
Answered by 12 days ago
Edited 12 days ago

Have you tried debugging. Also try removing the local on line 8. This creates a NEW Divisor variable, removing the local on line 8 will update the one declared in line 2 (don't remove the local on line 2). Maybe that is the problem.

You can also make this code more efficient and simplified if you use events and string.format to avoid messy concatenation.

local ContentProvider = game:GetService("ContentProvider") -- why name it Stats?
local divisor = 0

ContentProvider:GetPropertyChangedSignal("RequestQueueSize"):Connect(function()
    local request_queue_size = ContentProvider.RequestQueueSize

    if divisor <= request_queue_size then
            divisor = request_queue_size
    end
    script.Parent.Text = string.format("%d%% |%d| %d", 100*(1 - request_queue_size/Divisor), divisor, request_queue_size)
end)
0
changing the local fixed it Benbebop 118 — 12d
0
changing the local fixed it\ Benbebop 118 — 12d
Ad

Answer this question