I need help with the Connect() method

I want to know if you’re able to connect more than one function when a value changes

What I’ve been trying to do is check everytime the money value is changed in my game, but I’ve noticed adding GetPropertyChangedSignal for the same value on many scripts cause lag.
At first it looked like this

-- shop script
money:GetPropertyChangedSignal('Value'):Connect(function_1)
-- ^ compares cash, if you don't have enough money for an item color for ui_elements change

-- rebirth popup script
money:GetPropertyChangedSignal('Value'):Connect(function_2)
-- ^ when you have enough money it will prompt you if you want to rebirth

-- etc, I didn't show the whole functions but I told the purposes of them

But that caused lag spikes so I tried doing the method below instead

money:GetPropertyChangedSignal('Value'):Connect(function_1, function_2)

But this didn’t work, so I wonder if there is a way to either connect more than one function when a value changes or either improve or use a new method which causes less lag and is more efficient.

1 Like

Not really, the Connect function only has 1 parameter which is the function you want to connect to.

But you can call both in one function or combine them.

money:GetPropertyChangedSignal('Value'):Connect(function()
    function_1()
    function_2()
end)
local function function_3()
    -- shop script
    -- rebirth popup script
end

money:GetPropertyChangedSignal('Value'):Connect(function_3)
1 Like

the parenthesis after :Connect is for inputs in case if you want to put a value into a function and use it for something
Example:

local function add(a,b)
    return a + b
end

print(add(1,2))

you would get 3
As how to do different things using the same event you can write two different functions and use some If statements alongside with and, or

local function comparecash()
--compare cash and do things
end

local function rebirthprompt()
--activate the rebirth prompt
end

money.Changed:Connect(function()
if money.Value == something then
comparecash()
elseif money.Value == somethingelse or somethingelseelse and somethingelseelseelse then
rebirthprompt()
end
1 Like

A hacky solution would be the following

money:GetPropertyChangedSignal('Value'):Connect(function()
    function_1()
    function_2()
end)
2 Likes

uh
do you mind showing us the actual code you’re running?
this is odd. It seems to be a problem with function_2 then.

1 Like
-- function_2	
money:GetPropertyChangedSignal('Value'):Connect(function()
	if near_tycoon.Value == player_tycoon.Value and active_tycoon.Value then 
		if local_player.PlayerSettings.rebirth_alert.Value == true then 
			if canceled == false then
				prompt_rebirth_alert()
			end
		end
	end
end
local function_1 = function()

-- run your code

end

script.IntValue.Changed:Connect(function_1)
1 Like