I'm making a private message/notification system for fun. I have most everything down, but there is one bug I haven't been able to iron out. My system works like this: I type a command in the command bar which goes to a global function that takes a variable form the command and turns it into the text of a Message. That Message is put in the player object.
I just realized this is going to take a while to type, I'll just post the code and hope you understand it. If you need help deciphering my messy code just ask for an explanation.
player = game.Players.LocalPlayer gui = player.PlayerGui["Messages"].TextLabel iu = false waiting = {"Don't delete me ;_;"} deb = false deb2 = false removable = true function tweenin(text) iu = true gui.Text = text gui:TweenPosition(UDim2.new(0.25, 0, .125, 0), "Out", "Quad", 2, false) end function tweenout() gui:TweenPosition(UDim2.new(0.25, 0, -1, 0), "Out", "Quad", 2, false, function() iu = false end) end player.ChildAdded:connect(function(mes) if mes:IsA("Message") then print("Message recieved") if not iu then print("not iu") tweenin(mes.Text) gui.button.MouseButton1Click:connect(function() deb = true tweenout() mes:Destroy() wait(.5) deb = false end) else print("iu") table.insert(waiting, 1, mes.Text) repeat wait(1) until iu == false print(table.concat (waiting, ' ')) print(waiting[1].." going") tweenin(waiting[1]) gui.button.MouseButton1Click:connect(function() deb2 = true tweenout() if removable then print("removing") -- When it removes two things from the table this prints once, just like every other time. table.remove(waiting, 1) -- The only place that anything is ever removed from a table. print("removed") -- same as above, only prints once end removable = false mes:Destroy() repeat wait() until not iu wait(0.5) deb2 = false removable = true end) end end end)
Here's the output:
Message recieved not iu -- first message starts without having to wait Message recieved iu -- is waiting Message recieved iu -- is waiting Message recieved iu -- is waiting Gold 300, Experiance 5, Level 1, Don't delete me ;_; -- list of waiting message Gold 300 going -- is going to be next removing -- whichever just went gets removed removed Experiance 5, Level 1, Don't delete me ;_; Experiance 5 going removing removed Level 1, Don't delete me ;_; Level 1 going removing -- This only prints once, but the last index in the table (don't delete me) disappears without a trace.... removed
Thanks for any information you can give me, LightArceus
I have no idea how to fix what You made, because I don't actually see how that problem is produced.
EDIT: I answered with an answer for the question in the title by accident, that answer (the original answer)is below, in case it's ever any use.
local ot = false --define local variable ot as false if ot == false and #table > 1 then --if ot is false and there's more than one object in the table table.remove(table,-1) --remove last table.remove(table,-1) --remove last again ot = true --set ot to true elseif #table == 1 or ot == true and #table > 1 then --but if there's only one item in the table, or ot is true, and there's more table.remove(table,-1) --remove the last object in the table ot = false --set ot to false end --end