Hello. I made an E interaction to grab some items, yet, if there is an existing UI and you move to a closer existing one, it won’t create a new BillboardGui. I am really bad at explaining my issue, here is a video and my script:
https://streamable.com/js4310
My script:
local billbaord = script.Parent;
local userInputService = game:GetService("UserInputService");
local lastUI = nil;
local lastInteractable = nil;
local function input_Began(input, isTyping)
if isTyping then return end;
if input.KeyCode ~= Enum.KeyCode.E then return end;
local tweenService = game:GetService("TweenService");
local tweenInfo = TweenInfo.new(0.3);
local goal = {
Size = UDim2.new(0.428, 0,0.866, 0);
BackgroundColor3 = Color3.fromRGB(41, 82, 124)
};
tweenService:Create(lastUI.Around.Inside, tweenInfo, {
BackgroundColor3 = Color3.fromRGB(41, 82, 124)
}):Play()
local track = tweenService:Create(lastUI.Around, tweenInfo, goal);
track:Play()
lastUI.Around.Inside.InsideBar.Size = UDim2.new(0.34, 0,0.363, 0)
lastUI.Around.Inside.InsideBar.Visible = true
local track2 = tweenService:Create(lastUI.Around.Inside.InsideBar, TweenInfo.new(1), {
Size = UDim2.new(1, 0, 1, 0)
})
track2:Play()
userInputService.InputEnded:Connect(function(input, isTyping)
if isTyping then return end;
if input.KeyCode == Enum.KeyCode.E then
tweenService:Create(lastUI.Around, tweenInfo, {
Size = UDim2.new(0.528, 0,1.006, 0);
BackgroundColor3 = Color3.fromRGB(85, 170, 255)
}):Play()
tweenService:Create(lastUI.Around.Inside, tweenInfo, {
BackgroundColor3 = Color3.fromRGB(85, 170, 255)
}):Play()
lastUI.Around.Inside.InsideBar.Visible = false
track2:Stop()
else
end
end)
end;
userInputService.InputBegan:Connect(input_Began)
while wait() do
local closestPoint = 7;
local interactables = workspace.Interactables:GetChildren();
if lastInteractable and (game.Players.LocalPlayer.Character.UpperTorso.Position - lastInteractable.Position).Magnitude > closestPoint then lastUI:Destroy() else end
for _, v in ipairs(interactables) do
if (game.Players.LocalPlayer.Character.UpperTorso.Position - v.Position).Magnitude < closestPoint then
lastInteractable = v
local clone = script.Interaction:Clone();
clone.Parent = v;
lastUI = clone
repeat wait()
until (game.Players.LocalPlayer.Character.UpperTorso.Position - v.Position).Magnitude > closestPoint
lastUI:Destroy()
else
end
end
end