So I have cooldown indicators in my game, and they work, but they stack sometimes. For some unknown reason, Only updates the position when the frame gets created. Doesn’t work after. I have a feeling I’ve overlooked something, but I’m unsure.
cooldowns = {}
game.ReplicatedStorage.Remotes.CreateCooldown.OnClientEvent:Connect(function(ReloadTime, AttackType, AbilityName)
task.spawn(function()
local myTweenInfo = TweenInfo.new(ReloadTime, Enum.EasingStyle.Linear)
local gui = script.CooldownFrame:Clone()
gui.Parent = script.Parent
gui.AbilityName.Text = AbilityName
gui.Container.TextLabel.Text = AttackType
local z=table.insert(cooldowns,gui)
for i=1, #cooldowns do
print(i)
cooldowns[i].Position = UDim2.new(0.699,0,-0 + i / 10,0)
end
local myTween = game:GetService("TweenService"):Create(gui:FindFirstChild("Progress", true), myTweenInfo, {Size = UDim2.new(1, 0, 1, 0)})
myTween:Play()
task.wait(ReloadTime)
table.remove(cooldowns,z)
for i=1, #cooldowns do
if cooldowns[i] ~= gui then
print(i)
cooldowns[i].Position = UDim2.new(0.699,0,-0 + i / 10,0)
end
end
gui:Destroy()
end)
end)
Alright, so when a cooldown gets destroyed it returns nil, however I believe that’s the cooldown GETTING removed, hold on, I’ll make it ignore the one getting deleted.
You probably got the math wrong shouldn’t this be the size of the Frame, not some random number:
local Size = gui.AbsoluteSize
local ParentSize = gui.Parent.AbsoluteSize -- if it's parent is not a ScreenGui
-- else we need to get the size of the screen
-- if the parent is a ScreenGui
local function GetScreenSize(): Vector2
local ScreenGui= Instance.new("ScreenGui", PlayerGui)
local Frame = Instance.new("Frame", ScreenGui)
Frame.Size = UDim2.new(1, 0, 1, 0)
local ScreenSize = Frame.AbsoulteSize
ScreenGui:Destroy()
return ScreenSize
end
local UnitSize = if gui.Parent:IsA("ScreenGui") then Size / GetScreenSize() else (Size / ParentSize)
UDim2.new(0.699, 0, UnitSize * i,0)