im trying to make a dialog/text pop up once you press a part, i have a semi-working script for this but it’s a horrible script (i found it on a youtube video since i cant script by myself!) i need help with a script that makes it fade in, stays for a few seconds, then fades out. i also need this script to only happen once, once the part is pressed and only appear for the player that pressed it.
game.Workspace.Trigger.Touched:Connect(function(hit) if hit and hit.Parent then local debounce = true script.Parent.Visible = true script.Parent.TextTransparency = 1 wait(0.025) script.Parent.TextTransparency = 0.9 wait(0.025) script.Parent.TextTransparency = 0.8 wait(0.025) script.Parent.TextTransparency = 0.7 wait(0.025) script.Parent.TextTransparency = 0.6 wait(0.025) script.Parent.TextTransparency = 0.5 wait(0.025) script.Parent.TextTransparency = 0.4 wait(0.025) script.Parent.TextTransparency = 0.3 wait(0.025) script.Parent.TextTransparency = 0.2 wait(0.025) script.Parent.TextTransparency = 0.1 wait(0.025) script.Parent.TextTransparency = 0 wait(2) script.Parent.TextTransparency = 0 wait(0.025) script.Parent.TextTransparency = 0.1 wait(0.025) script.Parent.TextTransparency = 0.2 wait(0.025) script.Parent.TextTransparency = 0.3 wait(0.025) script.Parent.TextTransparency = 0.4 wait(0.025) script.Parent.TextTransparency = 0.5 wait(0.025) script.Parent.TextTransparency = 0.6 wait(0.025) script.Parent.TextTransparency = 0.7 wait(0.025) script.Parent.TextTransparency = 0.8 wait(0.025) script.Parent.TextTransparency = 0.9 wait(0.025) script.Parent.TextTransparency = 1 wait(0.025) script.Parent.Visible = false local debounce = false end end)
this is the script i currently have (it's hideous, i know) but i can't make it only happen once
Use TweenService
local TS = game:GetService("TweenService") local Label = script.Parent local Delay = 0.025 workspace:WaitForChild("Trigger").Touched:Connect(function(HitPart) if HitPart then local Tween = TS:Create(Label,TweenInfo.new(Delay),{TextTransparency = 1}) Tween:Play() Tween.Completed:Wait() wait(2) local Tween = TS:Create(Label,TweenInfo.new(Delay),{TextTransparency = 0}) Tween:Play() end end)
Is it a NORMAL script (server sided)? Is it a LOCAL script (client sided)?
if it's a NORMAL one, then delete it. If it's a LOCAL one, and you have it inside of a text LABEL, then please do the following:
local debounce = false -- just making the debounce variable and giving it the TRUE value, does not make it cooldown. local Part = workspace.Trigger -- don't do game.Workspace, just workspace. It will work the same.. (also use a lowercase w not uppercase W). local TextLabel = script.Parent -- assuming it's a TextLabel.. Part.Touched:Connect(function() if debounce then return end -- if db is true then stop the script here. debounce = true -- if it ISN'T false, then continue the script. while TextLabel.TextTransparency>0 do -- if transparency is OVER 0, continue running. task.wait(0.025) TextLabel.TextTransparency-=0.1 end task.wait(2) -- how long it will be on the screen for: while TextLabel.TextTransparency<1 do -- if transparency is UNDER 0, continue running. TextLabel.TextTransparency+=0.1 end debounce = false end) -- end function here.
By setting it to true, and if you touch the part again while it IS true, it will stop it from running as it's already true and not false.
The while loops will ONLY run when the condition is still true. So if the transparency was still over 0, it will continue running, bla bla bla.
I hope this helped! <3