How to make NumberValue.Value's new value save and work for other code?

I’ve got these two NumberValues that I’m using to determine the “max spread” and “inaccuracy step amount” of a gun. I declare them in the main local script with local MaxSpread = script.Parent.Values.MaxSpread.Value and local AimInaccuracyStepAmount = script.Parent.Values.AimInaccuracyStepAmount.Value. I’ve got another local script that manages aiming the gun and also changes the max spread and inaccuracy step amount values. The problem is that the main local script doesn’t accept these new values when it needs to use them. I’m not sure how to make the new values count.

Code that references these values, if that somehow helps:

if Spread and not DecreasedAimLastShot then
				Spread = math.min(MaxSpread, Spread + AimInaccuracyStepAmount)
				UpdateCrosshair(Spread)
			end
while true do
	wait(0.3)
	if Spread and not IsShooting then
		local currTime = time()
		if currTime - LastSpreadUpdate > FireRate * 2 then
			LastSpreadUpdate = currTime
			Spread = math.max(MinSpread, Spread - AimInaccuracyStepAmount)
			UpdateCrosshair(Spread, MyMouse)
		end
	end
	end

If you define the variables as a the value of the max spread or inaccuracy, then it will not change because the variables are just numbers. What you should do is define the variable as script.Parent.Values.MaxSpread and script.Parent.Values.AimInaccuracyStepAmount, without the .Value

Then, when you use it, replace MaxSpread with MaxSpread.Value, etc. Defining the variables to the numberValues themselves will account for the changes

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.