#Unable to change an intvalue in my script

1 messages · Page 1 of 1 (latest)

inland cloak
#
local PowerValue = workspace.DoorButton.ProximityPrompt.PowerScript.PowerValue.Value

while DoorClosed.Value == true do
    wait(0.5)
    PowerValue = PowerValue - 10
end

if PowerValue == 0 then
    print("Power outage!")
    workspace.DoorButton.ProximityPrompt.Enabled = false
end```

Does anybody know what's wrong with this script? The PowerValue never goes down, even if the door is closed, though the power-outage section of the script works. I've been unable to figure out how to get int/number values to go up or down, any help would be appreciated!
tidal fractal
#

Doing local PowerValue = workspace.DoorButton.ProximityPrompt.PowerScript.PowerValue.Value only makes a new variable called "PowerValue" with for its value, the value of your IntValue when you set the variable.

You just have to move .Value.

#
local DoorClosed = workspace.DoorButton.ProximityPrompt.DoorScript.DoorClosed;
local PowerObj = workspace.DoorButton.ProximityPrompt.PowerScript.PowerValue

while DoorClosed.Value == true do
    wait(0.5)
    PowerObj.Value -= 10
end

if PowerObj.Value == 0 then
    print("Power outage!")
    workspace.DoorButton.ProximityPrompt.Enabled = false
end
#

@inland cloak

inland cloak
#

Ok I'm trying this now to make sure it works

tidal fractal
#

Ok

inland cloak
#

I copied your script in the place of the old one, but the value still isn't going down, even if DoorClosed is true

tidal fractal
#

That is not normal

#

No error in the output?

inland cloak
#

Nope. I've been trying to do even more basic intvalue scripts and nothing I try can change a value

tidal fractal
#

Ok I'm gonna try it

#

I can make it decrease ._.

#

Something must be wrong with your instances or with the Value of DoorClosed

inland cloak
young geyserBOT
#

studio** You are now Level 1! **studio

inland cloak
#

It could be, though I don't think there's anything wrong with DoorClosed, as it's true

#

And everything else related to it works, so maybe instances then

tidal fractal
#

Add a print in between the wait and the value set in the while loop

#

If nothing prints, the bool gets set to false somewhere

#

If not, I have no clue

#

My last idea would be to use NumberValue but I think that makes no difference in your case

#

I just use way more NumberValues than Ints

inland cloak
#

Ok I added a print between those lines, and nothing is printing. I watched the DoorClosed bool and it switches as it should when the door opens/closes

#

I could try a number value and see if that changes anything

#

Ok I swapped it for a NumberValue and nothing changed

#

Honestly I'm at a loss, and consistantly every script I put an int/number value into breaks

tidal fractal
#

Ooh I think I get what you want, you want it to run the loop when the door closes?

#

The way you're doing it rn only checks at start of the game

inland cloak
#

Oooh

#

Ok so what would I need to do to fix this

tidal fractal
#
local DoorClosed = workspace.DoorButton.ProximityPrompt.DoorScript.DoorClosed :: BoolValue
local PowerObj = workspace.DoorButton.ProximityPrompt.PowerScript.PowerValue :: IntValue

local function OnDoorClose()
    if DoorClosed.Value then -- Is Closed
        repeat
            wait(0.5)
            PowerObj.Value -= 10
        until (not DoorClosed.Value)
    end
end

DoorClosed:GetPropertyChangedSignal("Value"):Connect(OnDoorClose)
OnDoorClose()

if PowerObj.Value == 0 then
    print("Power outage!")
    workspace.DoorButton.ProximityPrompt.Enabled = false
end
#

Try this

inland cloak
#

Ok this works

#

The power outage doesn't work but I think I can fix that

tidal fractal
#

Good, gl fixing the power outage

inland cloak
#

Alright thanks for the help :)