Hello, Im trying to make it so whenever the value off the ball changes, the text over the ball will set itself to the value of the ball.
Its not working, and its not erroring though.
The Script:
local Text = script.Parent.Text
local Cash = script.Parent:WaitForChild("Cash").Value
while true do
task.wait()
script.Parent:GetPropertyChangedSignal(Cash):Connect(TextChange)
function TextChange()
Text = tostring(Cash)
end
end
You shouldn’t put that property changed connection inside a while loop, i suggest you put it out. And there is not such property named “cash”, are you looking for a change in the cash’s value?
No, an if statement will run only once in the entire function/script, but an event will run the function everytime a change is detected. So you only need to connect the event once and your good
I tried to get the value of Cash ( a Instance within the NumberValue Class ) and it didn’t seem to work.
local Text = script.Parent.Text
local Cash = script.Parent:WaitForChild("Cash")
script.Parent:GetPropertyChangedSignal(Cash.Value):Connect(TextChange)
function TextChange()
Text = tostring(Cash)
end
2 problems. First, as @TenBlocke mentioned, it’s inside of a loop, which it shouldn’t be and second, you need to create the function before connecting it to an event.
local Text = script.Parent.Text
local Cash = script.Parent:WaitForChild("Cash")
function TextChange()
Text = tostring(Cash)
end
script.Parent:GetPropertyChangedSignal(Cash.Value):Connect(TextChange)
LUA runs much differently from Java, Python, or any other coding language that allows you to call functions before they are made. In LUA, if you call a function before it is created, it will lead to an error.
Ah my bad, I was focusing on the main problems. You need to change “Cash.Value” to just “Value,” you cannot reference the Text itself to change it, and you were adding the GetPropertyChangedSignal to the wrong Instance.
local Label = script.Parent
local Cash = script.Parent:WaitForChild("Cash")
function TextChange()
Label.Text = tostring(Cash.Value)
end
Cash:GetPropertyChangedSignal("Value"):Connect(TextChange)
local Text = script.Parent.Text
local Cash = script.Parent:WaitForChild("Cash").Value --- try with out the value
while true do
task.wait()
script.Parent:GetPropertyChangedSignal(Cash):Connect(TextChange)--- try text instead of cash, is cash a property of a Text thing?
function TextChange()
Text = tostring(Cash)
end
end
Ok so are you sure that the value is getting changed?
First i will ask you to do this and tell me what do you see in output
local Label = script.Parent
local Cash = script.Parent:WaitForChild("Cash")
function TextChange()
Label.Text = tostring(Cash.Value)
print("Function Executed!")
end
Cash:GetPropertyChangedSignal("Value"):Connect(TextChange)
print("Finished Execution!")
See that’s what I’m speaking about. If this is a local script then first place it in the StarterPlayerScripts. Now let’s say if this is a server script. This directly tells us that the code isn’t executing.
Is the value changing in the server? Are you even changing the value, if so then are you changing it locally in a localscript or in a normal server script