Hey! I am having an issue. My problem is that when i click on a part it is supposed to fade in a gui for 2 seconds and then it is supposed to fade out and the part is supposed to be destroyed as well as some values will be set to true. I know i am not doing right because the way i am doing it is very tedious. nonetheless it doesnt work. Here is my code please help me out.
local ClickDetector = script.Parent.ClickDetector
flashlight = game.ReplicatedStorage.Flashlight
local sound = script.Parent.Sound
-- Put this near the top of your script
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quint)
-- Use this where you want it to fade
tweenService:Create(ui, tweenInfo, {TextTransparency = 1}):Play()
This is a lot easier to use and works 100% of the time.
Hope this helps!
@ram4c TweenService is a lot easier and smoother than using a for or while loop.
Thank you for your reply! but i had plugged it into my script and replaced it with my old one but it still wont show up? am i doing something wrong here? This is what the script looks like:
You said fade for 2 seconds but you have “wait()” do you think that could be messing with the script try doing “wait (1)” or whatever time you wanna do when the transparency changes.
Well yes that could probably work, but i am trying to find a better way of making it fade in and out without having to type it over and over again. It is very tedious and if there is a better way of doing it i would like to use that one over my old one.
local function Changing ()
-- replace changing with what you want the functions name to be.
ui.TextTransparency = 0.5
wait()
ui.TextTransparency = 0.55
wait()
end
After that just make a few more different functions with different transparency.
The problem is that you’re defining your UI with game.StarterGui. UIs are not in StarterGui, they are cloned to the PlayerGui. Instead, you need to do
local ui = game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui').FlashLight.togflash
And as @Fire540Games said, TweenService is the best way to do this.
local TweenService = game:GetService("TweenService")
local info = TweenInfo.new(2) -- duration of the tween
local flashtween = TweenService:Create(ui, info, {TextTransparency = 1})
flashtween:Play()
Also, make sure that your script is a localscript and running from StarterGui, it will not work in a regular script running from the Workspace.
The error has nothing to do with the TweenService script.
Make sure you are defining your UIs/Parts correctly, I just took a wild guess since I don’t know the setup of your UI.
I looked at your code and I spotted some small errors. You deleted the ui and the script itself before setting the transparency and thats why there was a bit of trouble.
local ClickDetector = script.Parent.ClickDetector
flashlight = game.ReplicatedStorage.Flashlight
local sound = script.Parent.Sound
local ClickDetector = script.Parent.ClickDetector
flashlight = game.ReplicatedStorage.Flashlight
local sound = script.Parent.Sound
ClickDetector.MouseClick:Connect(function()
local ui = game.StarterGui.FlashLight.togflash
flashlight.Value = true
sound:Play()
ui:Destroy()
script.Parent:Destroy()
ui.TextTransparency = .95
wait()
ui.TextTransparency = .9
wait()