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

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

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

✓ Accepted answer

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

1 comment

0

+1 Cause effotr

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