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
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.
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
-- 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