Check if a local is changed

I’m not really sure on how .Changed works but I presume you can’t use that (I’m relatively new to scripting so I could 100% be wrong) so if i did

local h = "a"

       h = "b"

how would I detect if h was changed?

Best thing I can think of is making “h” into something such as a StringValue allowing you to use :GetPropertyChangedSignal() on it

I’ll try doing that and see if it works

My take would be checking each x amount of seconds if the value has changed.

You could also just set an Attribute of the script named h script:SetAttribute(“h”,“a”)

and use :GetAttributeChangedSignal

I think the good way is to make a value and through the script make a :GetPropertyChangedSignal() in this way you will get when its value changes and the following conditionals…

From docs:

local part ="Part")
-- Save the current state
local currentColor = part.BrickColor
local function onBrickColorChanged()
local newColor = part.BrickColor
print("Color changed from " .. currentColor.Name .. " to " .. newColor.Name)
currentColor = newColor


-- Make some changes
part.BrickColor ="Really red")
part.BrickColor ="Really blue")

Yeah but a local is way different to a part inside of workspace

1 Like

You must do it from the server script with the ‘FireEvent’, what you need is that when you click that happens and it is reflected in the server, right? (for all)

I can’t do it from a server script as it’s a localscript which has specific options per player

You could use a RemoteEvent to say what player the value needs changing for

The only way to detect a change of a local variable is to use a while loop that checks if the value has changed

local h = "a"
local old = "a"

       h = "b"

while h ~= old do
    old = h

    --Do other things here

Note that code afeter the while loop will not run until the while loop is stopped.

Maybe you could detect it by doing a function:

local runService = game:GetService("RunService")

-- Detect if change function
local function detectTextChanged(text, textValueOption)
	runService:BindToRenderStep('CheckValue', 1, function()
		if text ~= textValueOption then
			-- do something
			warn('Is not equal')
		if text == textValueOption then
			-- do something
			warn('is equal')

-- calling function:
local myText = "Hello"

detectTextChanged(myText, 'Hello') -- arguments here

-- I've thought of something like that, I'm not sure if it's what you need to do

Oops! forget, all this inside a while true or run service
RunService (


I just updated the code, check if it works