Value isn't changing

I got this script :

local fuel = game.ReplicatedStorage.Fuel.Value
local fuelLoss

game.ReplicatedStorage.Fuel:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.Humanoid.WalkSpeed = fuel/37.5
	script.Parent.LowerTorso.Fire.Size = fuel/60
	script.Parent.UpperTorso.PointLight.Range = fuel/30
	fuelLoss = 1/(2^(fuel/300))
	wait(fuelLoss)
	fuel = fuel - 1

end)

if fuel == 0 then
	script.Parent.Humanoid.Health = 0
end

Which is suppose to take the value of the player a make an operation. We wait the result, then remove 1 to the value, and repeat, problem is that value stored in RS doesn’t change. Why?

1 Like

On the first line, you grab the .Value of fuel. This means that the fuel variable now contains the Value of the Fuel compared to the Fuel object. It would need to be game.ReplicatedStorage.Fuel I believe.

Why use a GetPropertyChangedSignal for a Value instance? You could just use the Changed event instead, also try implementing print statements?

local fuel = game.ReplicatedStorage.Fuel
local fuelLoss

print("Script working")

fuel.Changed:Connect(function()
    print("Value changed")
	script.Parent.Humanoid.WalkSpeed = fuel.Value/37.5
	script.Parent.LowerTorso.Fire.Size = fuel.Value/60
	script.Parent.UpperTorso.PointLight.Range = fuel.Value/30
	fuelLoss = 1/(2^(fuel/300))
	wait(fuelLoss)
	fuel.Value -= 1
end)

if fuel.Value == 0 then
    print("Wut")
	script.Parent.Humanoid.Health = 0
end

I tried first with .Changed but it wasn’t working, so I tried with GetPropertyChangedSignal.

It seems that the problem come from the
fuel.Changed:Connect(function()
Line.
For some reasons, I think it doesn’t detect the value change (I just want to precise that I’m using IntValue)

Changed isn’t firing because you aren’t changing the value, or it wasn’t working because you are doing int.Changed over instance.Changed.

2 Likes
fuel.Value = fuel.Value - 1

At the beginning of the script (outdated version)

Can you double-check to make sure that you’re changing the value from the server-side? And not from the client?

It is server side, the script above is located in a script, stored in character

Can you check your Output for anything odd?

There’s nothing in relation with this script, I added proint statement :

local fuel = game.ReplicatedStorage.Fuel
fuel.Value = fuel.Value - 1
local fuelLoss

game.ReplicatedStorage.Fuel.Changed:Connect(function()
	print("Checking stats")
	script.Parent.Humanoid.WalkSpeed = fuel.Value/37.5
	script.Parent.LowerTorso.Fire.Size = fuel.Value/60
	script.Parent.UpperTorso.PointLight.Range = fuel.Value/30
	print('Changing Stats')
	fuelLoss = 1/(2^(fuel.Value/300))
	print('Calculating wait time beofre fuel loss')
	wait(fuelLoss)
	fuel.Value = fuel.Value - 1
	print('Fuel Lost')

end)

if fuel.Value == 0 then
	script.Parent.Humanoid.Health = 0
end

And any of these are shown in the output

The only thing I can think of is that you’re not changing the Value right, also

That line should be after the Changed Event if you want to detect that value change

Please for the sake of your health use

Value += 0.1

Instead of

Value = Value + 1

lol

1 Like

I’m not caring that much of this part of the script :,)
I’m trying to know why the script doesn’t detect my value change

Here is something that might work:

local replicatedStorage = game:GetService("ReplicatedStorage") -- sometimes getting the service makes it work
local fuel = replicatedStorage.Fuel -- don't get the Fuel.Value, it doesn't work

While setting a local variable from a global one, it won’t work if you get only the Value. (See my second line of script)
It should work with these changes. I hope it will !

It doesn’t seems to work either…
Value is still at 600 (default value)

Another thing that might be the problem:
Make the script wait before changing the value of Fuel. Maybe it’s changing before the other script being ready.

Everything is handled by the same script, so I don’t see why there should be a priority with this script. When the script is loaded, it remove 1 to the fuel value and then it should make the loop. The problem come from the changing value detection

Computers still need to read things before they can do what you tell them to.
Here, you’re changing the value before the computer knows that he needs to do something if the value is changed.
You need to put this line after your function:

fuel.Value = fuel.Value - 1

If you do this, the computer will know that there is a function connected if this value is changed. Otherwise it doesn’t and thus doesn’t fire the function (because it doesn’t know it exists yet).

Already did it at the beginning of the script.