I have a video below and it basically shows that when I walk away from the NPC, I get 2 ‘Tween started’ prints and 1 ‘Tween complete’ print instantly (no 5 second wait) and then the second print comes after 5 seconds. The UI isn’t tweening at all, it just deletes instantly
This is the function I call to delete the UI. I don’t know why it’s firing twice tho.
local function DeleteAction()
local ActionClone = PlayerGui:FindFirstChild('TalkAction')
if not ActionClone then return end
local ActionTween = TweenService:Create(ActionClone.Control, TweenInfo.new(5), {Size = UDim2.new(0, 0, 0, 0)})
ActionTween:Play()
print('Tween started')
ActionTween.Completed:Wait()
print('Tween complete')
ActionClone:Destroy()
end
The function that calls it
local function RenderStepped()
local LastInput = UserInputService:GetLastInputType()
NPC = nil
local Character = Player.Character
if Character then
local HumanoidRootPart = Character:FindFirstChild('HumanoidRootPart')
if not HumanoidRootPart then return end
for _, v in pairs(NPCs:GetChildren()) do
local Distance = (v.PrimaryPart.CFrame.Position - HumanoidRootPart.CFrame.Position).magnitude
if not NPC or Distance <= NPC.Distance then
NPC = {
Current = v,
Distance = Distance
}
end
end
if not NPC then return end
Distance = NPC.Distance
if Distance <= ReachableDistance then
local DialogueClone = PlayerGui:FindFirstChild('Dialogue')
if DialogueClone then return end
local ActionClone = PlayerGui:FindFirstChild('TalkAction')
if ActionClone then return end
local ActionClone = Action:Clone()
ActionClone.Name = 'TalkAction'
if LastInput == Enum.UserInputType.Touch then
ActionClone.Control.Tap.Visible = true
ActionClone.Control.Key:Destroy()
ActionClone.Control.Activated:Connect(function()
Start()
end)
end
ActionClone.Adornee = NPC.Current
ActionClone.Parent = PlayerGui
local ActionTween = TweenService:Create(ActionClone.Control, TweenInfo.new(0.25), {Size = UDim2.new(1, 0, 1, 0)})
ActionTween:Play()
else
DeleteAction() -- Called here
end
end
end
Basically deletes it when the player walks away