Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Checking IntValues through Controllers?

Asked by
elian11 10
7 years ago
Edited 7 years ago

I have some code which will only run if a value (IntValue) is 1 (1 = true).

It works great if I change the value before running the script, script finds value, runs accordingly, all good. The thing is, I'm trying to change the value of my variable through a controller in a different script.

gameRunning = game.Workspace.gameModel.gameRunning.Value

function touched() 
    gameRunning = 0
    print("game stopped")
end
script.Parent.Touched:connect(touched)

The gameRunning is the value I am talking about.

Then, the other script searches for the value when it is called. The controller is working fine, and to my knowledge it is telling the value to change it's value to 0. The thing is, nothing changes on the side of the code below. It still runs regardless if it's been changed in-game.

local brick = script.Parent
local i = 1
gameRunning = game.Workspace.gameModel.gameRunning.Value    

if brick.isAlive.Value == 1 and gameRunning == 1 then
    function touched() 
    while i < 50 do
        wait()
        brick.Transparency = i / 50
        i = i + 1

    end
        brick.CanCollide = false;
        brick.isAlive.Value = 0
    end
    script.Parent.Touched:connect(touched)
else
    print("Game not running")
end

Ideas? Could it be because my script isn't actually changing the value? Or is it that my controlled part is basing the value off the one the server originally loaded.

1 answer

Log in to vote
0
Answered by 7 years ago

The reason is because you are pre-setting the value to the variable and will not update to when the IntValue actually updates in game.

In order to fix this, just reference the intvalue itself:

gameRunning = game.Workspace.gameModel.gameRunning

And then whenever you need the value do:

gameRunning.Value == 1.

This means that it will receive the current updated value of the IntValue.

Ad

Answer this question