I am creating a fighting game, and when the player uses a move, it places a cooldown gui on the top-right corner of the screen. The cooldown gui system works fine but there’s a small issue with it. The thing is when a move gui that’s ontop of another gui disappears, it tweens up in it’s place. Sometimes when this happens it weirdly places itself in the wrong spot. Each of these guis are about 0.060 apart on the YScale part of Udim2, and when a gui above it disappears, it subtracts 0.060 from it’s original position to tween in it’s place. I am having a hard time finding the issue and would appreciate any help solving this. (The script is handled inside a module that has 3 arguments, cooldown being self-explanatory, name being the name of the move that’s being displayed on the gui, and the player being the player so the script can access their gui.) ALSO the cooldownnumber intvalue counts how many cooldown guis there are by raising/lowering the value everytime a gui is added/removed.
module.createCooldown = function(cooldown, name, player)
local died = false
local gui = player.PlayerGui.Misc:WaitForChild("CooldownGUI")
local placeholder = gui:WaitForChild("CooldownPlaceholder")
local cooldownUI = placeholder:Clone()
cooldownUI.Parent = gui
local cooldownNumber = gui.GuiNumber
cooldownUI.Name = "CooldownUI"
cooldownUI.Position = UDim2.new(0.878, 0, 0.025 + (0.060 * cooldownNumber.Value), 0)
cooldownNumber.Value += 1
cooldownUI.MoveName.Text = name
cooldownUI.Visible = true
local ts = game:GetService('TweenService')
ts:Create(cooldownUI.BarBackground.Bar, TweenInfo.new(cooldown, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Size = UDim2.new(0,0,1,0)}):Play()
gui.ChildRemoved:Connect(function(child)
for _, v in pairs(gui:GetChildren()) do
if v:IsA("Frame") and child:IsA("Frame") and v.Name == "CooldownUI" and not died then
if v.Position ~= UDim2.new(0.878, 0, 0.025,0) and child.Position.Y.Scale < v.Position.Y.Scale then
ts:Create(v, TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Position = v.Position - UDim2.new(0,0,0.060,0)}):Play()
end
end
end
end)
if player.Character:FindFirstChild("Humanoid") then
player.Character.Humanoid.Died:Connect(function()
cooldownUI:Destroy()
died = true
cooldownNumber.Value = 0
end)
end
task.delay(cooldown, function()
if not died then
cooldownNumber.Value -= 1
cooldownUI:Destroy()
end
end)
end