Is there any way to check changes in integer value from local script?

Is there any way to identify changes in integer value from local script?

I am currently using while true do loop for identifying changes in values and they lag the game, and “.Changed” also doesn’t work in local script.

I attached a code for example

location of the localscript
image

location of the textbox by which the value updates

I am trying to find a way other than while true do loop to find the change in the textbox text and update the integer value accordingly, textbox and IntValue and localscript all are in StarterGUI

I tried to find the solution on the dev forum but didn’t find anything for what I needed…

.changed works in localscripts, you sure you used it correctly?

1 Like

You can use GetPropertyChangedSignal

local mainvalue = game.Players.LocalPlayer.PlayerGui:WaitForChild("ATM_Gui").MainFrame.HolderFrame.Withdraw.Input

mainvalue:GetPropertyChangedSignal("Text"):Connect(function()
      --modified
end)

I don’t to see why .Changed wont work, are you doing it correctly?

local mainvalue = game.Players.LocalPlayer.PlayerGui:WaitForChild("ATM_Gui").MainFrame.HolderFrame.Withdraw.Input

mainvalue.Changed:Connect(function(property)
      --modified
end)

Also may I add you’re code uses while true do Without a task.wait(), I advice you not run that code unless you want studio to crash

1 Like

.Changed does work I have used it multiple times for script

I must have done any mistake, I’ll try it again

Use the GetPropertyChangedSignal function and make sure that the local script is somewhere it’ll run, like StarterPlayerScripts.

@danger_wolf8 Please read my post, it might help you!

This is code that works inside a local script and I use
This is for a Pet Inventory system but it still uses .Changed

Inv.Changed:Connect(function()
	script.Parent.Text = Inv.Value..'/'..MaxInv.Value
end)

Also try RunService instead of while true do as it doesn’t lag out as much i think

He was using a while true do without a task.wait(), of-course it will lag, it will fully crash his studio.

– But yes RunService is better

i know but with runservice you don’t need to add in a wait

Code:

local RunService = game:GetService("RunService")
--This seems to be a TextBox? Is it a string?
local MainValue = game.Players.LocalPlayer.PlayerGui:WaitForChild("ATM_Gui").MainFrame.HolderFrame.Withdraw.Input.Text

local OldValue
local NewValue

--Initialization
NewValue = MainValue.Value
OldValue = NewValue.Value

--Prevent lag
RunService.RenderStepped:Connect(function()
  OldValue = NewValue
  NewValue = MainValue.Value
  
  if (OldValue.Value ~= NewValue.Value) then
    --Value changed
  end
end)

I don’t know why but it still doesn’t work for me, I tried the same code, I updated the post please check it again

Is it for localscript?, I tried your code too but it is not updating the value, I updated the post please check it again so you can get more idea about my problem

Try this again:

local RunService = game:GetService("RunService")
local Source = game.Players.LocalPlayer.PlayerGui:WaitForChild("ATM_Gui").MainFrame.HolderFrame.Withdraw.Input
local OldValue
local NewValue

--Initialization
NewValue = Source.Text
OldValue = NewValue

--Prevent lag
RunService.RenderStepped:Connect(function()
  OldValue = NewValue
  NewValue = MainValue
  
  if (OldValue ~= NewValue) then
    --Value changed
  end
end)
1 Like

Worked very well, Thank you so much! :grinning:

Please do a small correction at line 13.

NewValue = Source.text

else everything works fine, thanks again!