I am trying to make it so when the value changes it fires a function in the same script.
Code:
folder:WaitForChild("Sweat"):GetPropertyChangedSignal("Value"):Connect(update("Sweat"))
Function:
function update(value)
print(value)
end
Error:
I have tried studio and roblox.
1 Like
blokav
(blokav)
April 10, 2022, 8:51pm
2
folder:WaitForChild("Sweat"):GetPropertyChangedSignal("Value"):Connect(update)
Whatever the new value of “Sweat” is will be passed into the “update” function.
Orbular3
(Orbular3)
April 10, 2022, 8:55pm
3
When connecting a pre-made function, you don’t need to add the brackets afterwards: instead just put the name:
function update(value)
print(value)
end
folder:WaitForChild("Sweat"):GetPropertyChangedSignal("Value"):Connect(update)
Or alternatively you could create the function in the line:
folder:WaitForChild("Sweat"):GetPropertyChangedSignal("Value"):Connect(function(value)
print(value)
end)
Since others have mentioned the issue, I’ll introduce something different to the table.
The StringValue object has a Changed event that passes the new value when Value was changed. More info can be found here: StringValue.Changed (roblox.com)
local strv = Instance.new("StringValue")
strv.Changed:Connect(function(str) print(str) end)
strv.Parent = game.Workspace -- No output
strv.Value = "Hello World!" -- Outputs "Hello World!"
You could just replace it with the code below. Another thing you could do is connect it into a function and then run the function which you wrote.
folder:WaitForChild("Sweat"):GetPropertyChangedSignal("Value"):Connect(function()
update("Sweat")
end)
Maybe this will work.
local Sweat = folder:WaitForChild("Sweat")
function Update()
local Value = Sweat.Value
end
Sweat:GetPropertyChangedSignal("Value"):Connect(Update)
Or try,
Folder:WaitForChild("Sweat"):GetPropertyChangedSignal("Value"):Connect(function()
Update("Sweat")
end)
A great way to debug things is to step through them in your mind.
Wait for child “Sweat” of folder
Get property changed signal “Value” of Sweat
Call update function with parameters “Sweat” which returns nil
Connect nil to property changed signal
What you probably wanted was:
Connect update function to property changed signal
So, we must connect the function instead of calling it first and connecting whatever it returns:
folder:WaitForChild("Sweat"):GetPropertyChangedSignal("Value"):Connect(update)
Also, note that the property changed signal doesn’t return the property, so:
local sweat = folder:WaitForChild("Sweat")
function update()
local value = sweat.Value
print(value)
end
sweat:GetPropertyChangedSignal("Value"):Connect(update)