Automatic reposition on GUI

I am working on a fighting game, and the fighting game has these cooldown guis, when one ends, the others should move back up and if a new one is made, the old ones should move back down.

So basically my cooldowns stalk on each other.

local CooldownGui = {}

local TweenService = game:GetService("TweenService")
local Gui = script:WaitForChild("CooldownBase")


function CooldownGui.new(Player, ReloadTime, AttackType, AbilityName)
	local PlayerGui = Player:WaitForChild("PlayerGui")
	local Character = Player.Character
	local myScreenGui = Gui.CooldownFrame:Clone()
	local alls = Gui.CooldownFrame:GetChildren()
	myScreenGui.AbilityName.Text = AbilityName
	myScreenGui.Container.TextLabel.Text = AttackType
	local position = Instance.new("NumberValue",myScreenGui)
	position.Name = "LineNumber"
	position.Value = PlayerGui.CooldownsGui.AmountOfCooldowns.Value + 1
	PlayerGui.CooldownsGui.AmountOfCooldowns.Value = PlayerGui.CooldownsGui.AmountOfCooldowns.Value + 1
	local status = nil
	local samedigits = 0
	for i=1, #alls do
		local check = alls[i]:FindFirstChild("LineNumber")
		if alls[i] ~= myScreenGui then
			if check ~= nil then
				if check.Value ~= PlayerGui.CooldownsGui.AmountOfCooldowns.Value then
				samedigits = samedigits + 1
				end
			end
		end
	end
			if samedigits == 0 then
				status = true
			else
				status = false
	end
	wait()
	if status == true then
		myScreenGui.Position = UDim2.new(myScreenGui.Position.X.Scale,0,myScreenGui.Position.Y.Scale + PlayerGui.CooldownsGui.AmountOfCooldowns.Value / 10 ,0)
	else
		myScreenGui.Position = UDim2.new(myScreenGui.Position.X.Scale,0,myScreenGui.Position.Y.Scale + PlayerGui.CooldownsGui.AmountOfCooldowns.Value / 10 + 1,0)
	end	
	myScreenGui.Parent = PlayerGui.CooldownsGui
	myScreenGui.tween.time.Value = ReloadTime
	myScreenGui.tween.Disabled = false
	local blabla = 0
	local myTweenInfo = TweenInfo.new(ReloadTime, Enum.EasingStyle.Linear)
	local blas = script.blas:Clone()
	blas.Parent = PlayerGui.CooldownsGui
	local myTween = TweenService:Create(blas.Frame, myTweenInfo, {Size = UDim2.new(1, 0, 1, 0)})
	myTween:Play()
	myTween.Completed:connect(function()
		wait()
		blas:Destroy()
		PlayerGui.CooldownsGui.AmountOfCooldowns.Value = PlayerGui.CooldownsGui.AmountOfCooldowns.Value - 1
		for i=1, #alls do
			local check = alls[i]:FindFirstChild("LineNumber")
			if check ~= nil then
				print("hi")
					check.Value = check.Value - 1
				end
end
	--	--could be flashier
	--	myScreenGui:Destroy()
	--	PlayerGui.CooldownsGui.AmountOfCooldowns.Value = PlayerGui.CooldownsGui.AmountOfCooldowns.Value - 1
	end)
end







return CooldownGui

If you wonder, yes the script is a modified version of the new crossroad’s reload system
How would I make it reposition?

Local Side;

local TweenService = game:GetService("TweenService")
local myTweenInfo = TweenInfo.new(script.time.Value, Enum.EasingStyle.Linear)
local myScreenGui = script.Parent
local current = myScreenGui.Parent.AmountOfCooldowns.Value
local myTween = TweenService:Create(myScreenGui:FindFirstChild("ProgressFrame", true), myTweenInfo, {Size = UDim2.new(1, 0, 1, 0)})
myTween:Play()
myTween.Completed:connect(function()
	--could be flashier
	myScreenGui:Destroy()
end)
local oldy = myScreenGui.Position.Y.Scale
--myScreenGui.Parent.AmountOfCooldowns.Changed:Connect(function(newval)
--	if current < newval then
--		myScreenGui.Position = UDim2.new(myScreenGui.Position.X.Scale,0,oldy + script.Parent.LineNumber.Value / 10,0)
--		print("Changed!")
--	end
--end)
1 Like