Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Checking IntValues through Controllers?

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

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.