Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Text Not Updating Properly?

while wait() do
	print(script.Parent.Parent.Amount.Value)
if script.Parent.Parent.Amount.Value > 0 then
	script.Parent.Visible = true
	script.Parent.Text = script.Parent.Parent.Amount.Value	
elseif script.Parent.Parent.Amount.Value < 1 then
	script.Parent.Visible = false
end	
end

No Errors

The problem is that when i change the value of amount it still prints 0, so the text does not update even though the value of amount isnt 0

1 answer

✓ Accepted answer

Events

This may actually not fix the issue, but I'd like to take this moment to encourage good standards - Do not use polling when waiting for events

By using the Value.Changed event, we can get the code to run only when there is actually a change in the value.

script.Parent.Parent.Amount.Changed:connect(function(val)
  print(val); -- val is the new value for after the change
  script.Parent.Text = val; -- Doesn't matter if you can't see it. Set it.
  script.Parent.Visible = val > 0; -- Comparison expressions are cast to booleans anyway.
end);

This discussion is preserved as it was. New answers, comments, and votes are closed.