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

Double Subtracting Values?

Asked by 10 years ago

My script is subtracting the Value - 2 every second instead of - 1 and no, no other script is doing - 1 in case someone was curious. I don't know why it is doing this, that is why I am asking for your help!

while wait(1) do
    for i,v in pairs(game.Players:GetChildren()) do
        if v:FindFirstChild("PointBooster1") then
            if v:FindFirstChild("PointBooster1").Value - os.time() > 0 then
                v:FindFirstChild("DoublePoints").Value = true
                print(os.time())
                print(v:FindFirstChild("PointBooster1").Value - os.time())
                v:FindFirstChild("PointBooster1").Value = v:FindFirstChild("PointBooster1").Value - 1
            else
                if v:FindFirstChild("DoublePoints") then
                    v:FindFirstChild("DoublePoints").Value = false
                end
            end
        end
    end
end

Do you guys see anything wrong or know what the problem may be? I print os.time() and it is only printing once every second so I know that isn't the problem, I have no idea why it is doing this, but please HELP! Thanks!

0
Can you fix the code block? ultrabug 306 — 10y
0
Fixed the code block. BornLeader1 5 — 10y
0
Note: os.time gets the client time therefor if anyone changes their clock time, weird stoof will happen. Bebee2 195 — 10y
0
It is a server - side script so I don't think much will happen. I am only printing it there for the reason of seeing if an actual second is passing or is it lagging or something. Anyway, is there any solutions? BornLeader1 5 — 10y
0
os.time on ROBLOX returns the true unix time when used in a server script. I am unsure of LocalScript behaviour. Articulating 1335 — 10y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

A stylistic note: There is no point to using FindFirstChild when you aren't actually doing error checking. This means there should be exactly two appearances of it in this excerpt.

Beyond this, it's not possible for this single script to be reducing each by more than one per second.

Are you certain there is only this script running? If you isolate it in a completely new place, does it behave correctly?

Also, an unrelated concern, are you sure your check for the existence of DoublePoints isn't necessary in the other (time-based) if?

Anyway, here's what I suggest is a cleaned up version, but I see no reason to think that this is causing what you are describing:

while wait(1) do
    for i,v in pairs(game.Players:GetChildren()) do
        if v:FindFirstChild("PointBooster1") then
            if v.PointBooster1.Value > os.time() then
                v.DoublePoints.Value = true
                print(os.time())
                print(v.PointBooster1.Value ,">", os.time())
                v.PointBooster1.Value = v.PointBooster1.Value - 1
            else
                if v:FindFirstChild("DoublePoints") then
                    v.DoublePoints.Value = false
                end
            end
        end
    end
end
Ad

Answer this question