Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 1 year ago

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.

0
you did not set db to false so it only works once Puppynniko 1059 — 1y
0
in what script? hellmet1 42 — 1y
0
both of them Puppynniko 1059 — 1y

1 answer

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
1 year ago

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)
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. hellmet1 42 — 1y
0
did you set the click detector path? Puppynniko 1059 — 1y
0
By that do you mean like the name of the Part that has the clickdetector? Yeah i did hellmet1 42 — 1y
0
is the script the child of the frame you want to fade in and out Puppynniko 1059 — 1y
View all comments (11 more)
0
Yeah it is hellmet1 42 — 1y
0
it should work is there any errors? Puppynniko 1059 — 1y
0
No, Strangely there aren't any errors, maybe it has to do with the properties of the frame.. I don't really know hellmet1 42 — 1y
0
your frame's visible property is set to false if not try testing it on a new frame Puppynniko 1059 — 1y
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. hellmet1 42 — 1y
0
Set the transparency to 1 on a normal frame but if theres other things you'll have to use a For loop Puppynniko 1059 — 1y
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? hellmet1 42 — 1y
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. hellmet1 42 — 1y
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 Puppynniko 1059 — 1y
0
Oh alright, i fixed it, thank you so much for helping dude! hellmet1 42 — 1y
0
np Puppynniko 1059 — 1y
Ad

Answer this question