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

Double Subtracting Values?

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!

5 comments

0

Can you fix the code block?

0

Fixed the code block.

0

Note: os.time gets the client time therefor if anyone changes their clock time, weird stoof will happen.

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?

0

os.time on ROBLOX returns the true unix time when used in a server script. I am unsure of LocalScript behaviour.

1 answer

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

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