What I’m trying to achieve is basically just UI Collision, in other words, to detect if a gui is touching a certain gui and if it is, move the gui thats being touched to the left and if the left is occupied moving another gui being touched to the right. My method is not very ideal.
local PlayerGui = game:GetService("Players").LocalPlayer.PlayerGui
local UIs = {}
function Reposition(ImageLabel,r)
if r then -- 1 goes to left
TweenService:Create(ImageLabel, TweenInfo.new(0.5), {Position = ImageLabel.Position - UDim2.new(0.2,0,0,0)}):Play()
else
TweenService:Create(ImageLabel, TweenInfo.new(0.5), {Position = ImageLabel.Position + UDim2.new(0.2,0,0,0)}):Play()
end
end
function CheckPosition()
if PlayerGui.Pocketer:FindFirstChild("Killa1") then
Reposition(PlayerGui.Pocketer.Killa1.Frame, true)
return UDim2.new(0.475, 0,0.921, 0)
end
if PlayerGui.Pocketer:FindFirstChild("Killa2") then
Reposition(PlayerGui.Pocketer.Killa2.Frame, false)
return UDim2.new(0.475, 0,0.921, 0)
end
return UDim2.new(0.475, 0,0.921, 0)
end
function CreateGui()
local GUI = game:GetService("ReplicatedStorage").ScreenGui:Clone()
GUI.Frame.Position = CheckPosition()
GUI.Name = "Killa"..#UIs
GUI.Parent = game:GetService("Players").LocalPlayer.PlayerGui.Pocketer
TweenService:Create(GUI.Frame, TweenInfo.new(0.4), {Size = UDim2.new(0, 255,0, 100)}):Play()
table.insert(UIs, #PlayerGui.Pocketer:GetChildren())
task.delay(4,function()
GUI:Destroy()
table.remove(UIs, #PlayerGui.Pocketer:GetChildren())
print(#UIs)
end)
GUI.Destroying:Once(function()
UIs[GUI.Frame] = nil --ignore.
print(#UIs)
end)
end