I want to make a text prompt that appears on screen whenever the player is within a part. There hasn’t been any issues until I tried implementing a tweened fade in/out. While it works sometimes, there are some noticeable inconsistencies – namely the tween stopping midway and leaving the text semitransparent, text simply not showing up, and the tween getting skipped altogether. I figure this has to do with the tweens overlapping, but I don’t really know what I could do if stopping the previous tween beforehand still causes issues as seen below.
local proxPart = game.Workspace.InteractPart
local localPlr = game.Players.LocalPlayer
local prompt = localPlr.PlayerGui.InteractPrompt.ScreenGui
local text = prompt.TextBox
local tt = text.TextTransparency
local char = localPlr.Character
local ts = game:GetService("TweenService")
local fade = TweenInfo.new(
0.3,
Enum.EasingStyle.Quad,
Enum.EasingDirection.InOut
)
local fadeInTransparency = 0
local fadeIn = ts:Create(text, fade, {TextTransparency = fadeInTransparency})
local fadeOutTransparency = 1
local fadeOut = ts:Create(text, fade, {TextTransparency = fadeOutTransparency})
local function enablePrompt(hit)
if hit.Parent == char and prompt then
if prompt.Enabled == false then
prompt.Enabled = true
end
if fadeOut.PlaybackState == Enum.PlaybackState.Playing then
fadeOut:Pause()
end
fadeIn:Play()
end
end
local function disablePrompt()
if prompt then
if fadeIn.PlaybackState == Enum.PlaybackState.Playing then
fadeIn:Pause()
end
fadeOut:Play()
fadeOut.Completed:Wait()
if tt == 1 then
prompt.Enabled = false
end
end
end
proxPart.Touched:Connect(enablePrompt)
proxPart.TouchEnded:Connect(disablePrompt)