How do you update a function when a value changed

  1. I want to try making an upgraded that will increase the upgrade amount every time the player presses the button

  2. so the code that upgrades the ore won’t update when the value is changed

  3. I’ve tried using intValue.changed and also searched the web for help

local value = script.Parent.Value.Value --the value is a intvalue

script.Parent.Upgrader.Touched:connect(function(Part)
	if Part:FindFirstChild("Cash") then
		print(value)
		
	end
		end)
		--Part.Cash.Value = Part.Cash.Value + value
		
1 Like

Have you checked that the object actually has the Cash IntValue in it and not in a Model or non-Part object?

Also, use :Connect instead of :connect.

1 Like

Yes, :connect() is deprecated; along with other methods such as :wait()

local value = script.Parent:FindFirstChild("Value")
local debounce = false

script.Parent.Upgrader.Touched:Connect(function(hit)
	if debounce == false then
		debounce = true
		
	    if hit:FindFirstChild("Cash") then
	        hit.Cash.Value = hit.Cash.Value + value.Value
	    end
		
        wait(1)
        
        debounce = false
    end
end)

Maybe that those objects don’t exist. I also added a debounce for 1 second so everything doesn’t go crazy. So pretty be sure all of your objects actually exist.

2 Likes

Even though its depreciated that is obviously not the source of the error, since “connect” still works. Is this a local or server script?

1 Like

I didn’t state that it was. I simply stated the fact that you shouldn’t use it because it is deprecated.

1 Like

Sure it is good practice to not use it but they both point to the same function so???

depreciated, my bad. No difference, use what you like.

Deprecated functions may be removed in the future or have unpredictable behavior. This is why it is good practice.

Though, sometimes they’re just deprecated in favor of a more updated or newer or cleaner version I believe like how raycastparams replaced the ray object casting. :connect is deprecated in favor of PascalCase when Roblox didn’t use PascalCase at the time.