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
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