Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i make it so that when i click a part a fading in and out gui appears?

I've been trying to make it so that when you click a part there's a black gui that fades in and fades out for a week and could'nt make it. I've tried using this script wich i put in the GUI

local debounce = false
local faded = false

game.ReplicatedStorage.FadeGui.OnClientEvent:Connect(function()
    if debounce == false then
        debounce = true
        if faded == false then
            faded = true
            for i = 0, 1, 0.05 do
                script.Parent:WaitForChild(THE GUI OBJECT YOU WANNA FADE).BackgroundTransparency = i
                wait(.05)
            end
            return -- returning to the beginning of the function to not run the following lines, after setting "faded" to true
          else
            faded = false
            for i = 1, 0, -0.05 do
                script.Parent:WaitForChild(THE GUI OBJECT YOU WANNA FADE).BackgroundTransparency = i
            wait(.05)
        end
        debounce = false
    end
end)

And then i put this script in the part

script.Parent.ClickDetector.MouseClick:Connect(function(Character)
game.ReplicatedStorage.FadeGui:FireClient(game.Players:WaitForChild("Character.Name")) -- Making a signal
end)

But it didn't work. Then i tried using this script but when i change it it stops working:

--< Variables >
local part = game.Workspace.ClickMe

local frame = script.Parent.Frame 

local db = false 

local TimeBetweenFade = 3 
--< Set up >
frame.BackgroundTransparency = 1
frame.Visible = true
--< Event >
part.ClickDetector.MouseClick:Connect(function() 
	if not db then 
		db = true
		
		for i = 1,0,-0.1 do
			frame.BackgroundTransparency = i
			wait(0.01)
		end
		 		
		print("Faded In") 
		
		wait(TimeBetweenFade)
		db = false 
		 
		for k = 0,1,0.1 do
			frame.BackgroundTransparency = k 
			wait(0.01) 
		end
		
		print("Faded out") 
		
		
	end
end)

Example, if i change the TimeBetweenFade, it stops working. Could anyone please tell me how to do it. Oh and just to clarify, these aren't my scripts, I just found them.

3 comments

0

you did not set db to false so it only works once

0

in what script?

0

both of them

1 answer

✓ Accepted answer

place in the frame and define your clickdetector

local Frame = script.Parent
local ClickDetector = workspace.Part.ClickDetector
local TweenS = game:GetService("TweenService")
local Db = false
local FadeTime = .5
ClickDetector.MouseClick:Connect(function()
	if not Db then
		Db = true
		TweenS:Create(Frame,TweenInfo.new(FadeTime),{BackgroundTransparency = 0}):Play()
		task.wait(FadeTime)
		TweenS:Create(Frame,TweenInfo.new(FadeTime),{BackgroundTransparency = 1}):Play()
		task.wait(FadeTime) --waits for the last tween to finish
		Db = false
	end
end)

15 comments

0

It still doesn't work. I've tried putting this localscript in the Frame and it didn't work, then in the Gui but it still didn't work.

0

did you set the click detector path?

0

By that do you mean like the name of the Part that has the clickdetector? Yeah i did

0

is the script the child of the frame you want to fade in and out

0

Yeah it is

0

it should work is there any errors?

0

No, Strangely there aren't any errors, maybe it has to do with the properties of the frame.. I don't really know

0

your frame's visible property is set to false if not try testing it on a new frame

0

Yeah it is, but how am i supposed to see if it is set to true? Maybe I'll just try setting the transparency to 1. If it still doesn't work I'll test it in a new game.

0

Set the transparency to 1 on a normal frame but if theres other things you'll have to use a For loop

0

Alright, i managed to make it work, the thing is that if i set it to ten it takes a lot of time to fade, how do i fix that?

0

Oh another thing, if there's many parts with the same name it won't work and for some reason it doesn't detect the clickdetector.

0

is it the wait thats too long if so you can change it in line 10 Task.Wait() also the reason i dont use Tween.Completed is cus its very late/it does not fire when it finished exactly and the reason it does not detect the clickdetector is sometimes roblox is bad at detecting if your mouse is on the part

0

Oh alright, i fixed it, thank you so much for helping dude!

0

np

This discussion is preserved as it was. New answers, comments, and votes are closed.