You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I’m trying to make a script that will update stats each time their value gets changed. -
What is the issue? Include screenshots / videos if possible!
I want to be able to send the value of the NumberValue, along with the NumberValue that was updated.
However, I keep getting an error message. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I couldn’t find any other people talking about this, and I also checked the developer hub page on Events. I also made sure that the functions and values were all spelled correctly.
Here is the code for the function and :Connect() event:
function onUpdate(value,stat)
local value = math.ceil(value)
local stat = nil
if stat == health then
-- Update value
elseif stat == hunger then
-- Update value
elseif stat == thirst then
-- Update value
elseif stat == stamina then
-- Update value
else
warn("Stat doesn't exist")
end
end
for _, stat in ipairs(stats:GetChildren()) do
stat.Changed:Connect(onUpdate(stat))
end
I also tried changing the order of the parameters:
function onUpdate(stat,value)
-- code goes here
end
for _, stat in ipairs(stats:GetChildren()) do
stat.Changed:Connect(onUpdate(stat,stat.Value))
end
Along with trying onUpdate(stat.Value,stat), I’m out of ideas here.
If it’s impossible to sent parameters this way, let me know and I’ll just figure something else out.
Thanks for your time