How would I optimize this button highlighting script

I have a script that highlights a button if the player has the points >= the button cost. I want to not use loops for this script and optimize it.

Here is the script

local highlight = button.SelectionBox

repeat
	task.wait(1)
until
tonumber(points.Value) >= 15
highlight.Visible = true
button.Material = Enum.Material.Neon

use :GetPropertyChangedSignal("Value") or .Changed. I believe this is the best way. Whenever the value you’re looking for changes, check if it’s validates your threshold, and if it does, disconnect the event and highlight the button. BUT, when you’re dealing with values, you can just use .Changed. Use .Changed.

local connection
connection = points.Changed:Connect(function()
    if points.Value >= 15 then
        connection:Disconnect()
        highlight.Visible = true
        button.Material = Enum.Material.Neon
    end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.