I have been trying to make an 'undo' function that you usually have in text editors and programs. I already did make sort of an 'undo' function, but it only removes 1 letter at a time, which is not what i am aiming for. I am going for something that removes whole words at a time.
I used GetPropertyChangedSignal
on the TextBox that I input the text into and store the strings in there, and then whenever a player presses ctrl + z, I first set the textbox's text to the last value of the table, and then delete that last value.
Here is the code that I used (not the exact, the variable are different of course):
local Tab = {};
Box:GetPropertyChangedSignal("Text"):Connect(function()
Tab[#Tab + 1] = Box.Text;
end);
game:service'Players'.LocalPlayer:GetMouse().KeyDown:Connect(function(key)
if key == "z" then -- i will add a ctrl check later.
Box.Text = #Tab > 0 and Tab[#Tab] or "";
Tab[#Tab] = nil;
end;
end);
As I mentioned earlier on, I want it to remove whole words at a time.
I am thinking of using pattern matching (string.gsub
, string.match
, %s+
, %w+
) to remove whole words at a time.
That is as far as I have gotten. Help would be much appreciated.