Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a better way to write this other than using a while loop?

Asked by
MediaHQ 53
4 years ago

I am trying to make a keypad that multiply's a code by whichever number the player puts. I am trying to make it so if the code changed then it changes the code but I think there might be a better way to write this. Is there a better way to write this?

local code = script.Parent.Code

local text = script.Parent

while wait(1) do
    text.Text = code.Value
end

1 answer

Log in to vote
2
Answered by 4 years ago

You can use an event named Changed on the value.

Note: the event Changed fires when any properties are changed, I suggest you follow it up with an if statement.

Sample script of a newly created part when it changed it's name

local Part = Instance.new('Part',workspace)

Part.Changed:Connect(function(property)
    print('part property changed: ',property)
end)

Part.Name = 'wow potato' -- the event fires.
Part.Transparency = .5 -- the event also fires here

Another example but using a GetPropertyChangedSignal which returns an event of when that specific property is changed.

local Part = Instance.new('Part',workspace)

Part:GetPropertyChangedSignal('Name').Connect(function()
    print('cool name change')
end)

Part.Name = 'wow potato' -- the event fires.
Part.Transparency = .5 -- the event doesnt fire here cuz it only fires when the name property has been changed
0
+1 Cause effotr User#30567 0 — 4y
Ad

Answer this question