I’ve created an indicator Gui that informs the player whenever an item gets added to their inventory. This is done through a bindable event that fires every time when an item gets added, which sometimes can be multiple times in a second.
I used tweens to tween each indicator Gui onto the screen and out of the screen. However, if the bindable event fires when an indictor is tweening in, that tween then breaks, resulting in:
This is the code responsible for the event and the tweening:
local event = script.Parent:WaitForChild("Indicate")
local IDs = require(game.ReplicatedStorage:WaitForChild("Items"):WaitForChild("!IDs"))
local rarity = IDs["rarityColours"]
local temp = script.Parent:WaitForChild("Templeate")
local frame = script.Parent:WaitForChild("Frame")
local queue = {}
local T = game:GetService("TweenService")
local TI = TweenInfo.new(0.5,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out)
event.Event:Connect(function(StringID)
local indication = frame:FindFirstChild(StringID)
if table.find(queue,StringID) and indication and indication.Position.Y.Scale > 0.1 then
indication.Count.Value += 1
indication.Text = IDs[StringID][1].Name.." x"..indication.Count.Value
else
local I = temp:Clone() -- Indication
for i,indication in pairs(frame:GetChildren()) do
T:Create(indication,TI,{Position = indication.Position - UDim2.new(0,0,temp.Size.Y.Scale,0)}):Play()
end
local posToMove = I.Position
I.Position = posToMove - UDim2.new(I.Size.X.Scale,0,0,0)
T:Create(I,TI,{Position = posToMove}):Play()
I.Parent = frame
I.Name = StringID
table.insert(queue,1,StringID)
I.Text = IDs[StringID][1].Name
I.Visible = true
wait(5)
I.Name = "old"
table.remove(queue,table.find(queue,StringID))
if I.Position.Y.Scale < 0 then
I:Destroy()
else
T:Create(I,TI,{BackgroundTransparency = 1, TextTransparency = 1, TextStrokeTransparency = 1}):Play()
wait(0.5)
I:Destroy()
end
end
end)