So i’m making a battery that generates power, But the value in the battery doesn’t change at all.
local Power = script.Parent.PowerStored.Value
local MaxPower = 100
while true do
if workspace.testgenerator.Active.Value == true then
wait(1)
if Power < MaxPower then
Power = Power + 5
print("Added 5 power")
elseif Power > MaxPower then
Power = MaxPower
print("Full!")
end
end
wait()
end
I have no clue why this happens it has happened before.
Edit: It changes in the script, But not the actual value inside the model.
local Power = script.Parent.PowerStored
local MaxPower = 100
function test()
while wait() do
if workspace.testgenerator.Active.Value == true then
wait(1)
if Power.Value < MaxPower then
Power.Value = Power.Value + 5
print("Added 5 power")
elseif Power.Value > MaxPower then
Power.Value = MaxPower
print("Full!")
end
end
end
end
test()
Hello. When you declare the first variable, Power, you are asigning it a value, not a reference to a value. For example, let’s suppose that PowerStored’s value is 5. Now this statement: local Power = script.Parent.PowerStored.Value
and this other one: local Power = 5
are equivalent. As you see, Power is a constant, there is no reference to any object. Thus, any change made to the PowerStored value is not detected.
Try to asign the object to the variable instead, as @3Kropek just suggested.