Okay, so the question may not make sense what I am trying to say. So here is what I am trying to say. In the bloxburg you know how their gui fades in when you get closer to a object. But when you walk away from it the gui fades out. What I mean by fade in is that when you already closer to the object, and when you fade out means you just go away from it. Even if you click the object I want to know how. Also, this is not a REQUEST one.
local gui = script.Parent gui.Visible = false wait(1) gui.Visible = true for i = 1,0,.1 do gui.Transparency = i wait(.2) end
Hi,
You can make a GUI fade in and out by a variety of methods. One of the easiest ones to understand is using a while loop. The code is below, which I will explain. Before I continue, it is good practice to shorten the names of the destination, such as:
local textVisible= game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Visible
However my Studio is clunky today, so I have the full destination address for use.
--part 1 local part= Instance.new("Part",game.Workspace) local partClickDetector= Instance.new("ClickDetector", part) --part 2 local screenGUI= Instance.new("ScreenGui",game.StarterGui) local textLabel= Instance.new("TextLabel",screenGUI) textLabel.Position= UDim2.new(0.5,0,0.5,0) textLabel.Size= UDim2.new(0.2,0,0.1,0) textLabel.Visible= false --part 3 function onPartClicked() if game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Visible== false then game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Visible= true --print(game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Visible) elseif game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Visible== true then game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Visible= false --print(game.Players.LocalPlayer.PlayerGui.ScreenGui.TextLabel.Visible) end end workspace.Part.ClickDetector.MouseClick:connect(onPartClicked) --part 4 local player= game.Players.LocalPlayer while true do if game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").TextLabel.Visible== true then local distance= player:DistanceFromCharacter(part.Position) --print(distance) local distanceMod= ((distance/100)*5)-0.25 --print(distanceMod) game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").TextLabel.Transparency= distanceMod end wait() end
The first part, you can instantiate the part, and in it, a click detector that will detect a user that clicked on the part. The part will first be placed in the workspace, and the click detector in part.
Next, you can create a ScreenGui, which will be placed in the Starter Gui. The Text Label will then be placed in the ScreenGui. Be sure to set the position and size of the GUI, which required Udim2.new(), which includes the scale and offset: (x scale, x offset, y scale, y offset). To start you can keep the GUI invisible until you click on the part.
Next, you need a function that turns on and off the GUI. The if-then statement says if the GUI is off, turn it on, and vice versa. You can print out the result to make sure the click function is working. Finally, you would need to bind the player clicking on the part, to the function, which is the last line in part 3.
In part 4, you can use DistanceFromCharacter to increase or decrease the transparency of the GUI. It first checks that the the GUI is visible (I know I added extra functionality because of turning off and on by mouse click). If so, it will begin taking the distance for each period of wait(). I can pair the distance with the transparency of the TextLabel GUI. But because the transparency value goes from 0-1, you can scale the distance, and adjust as you like on how far you are from the part in order for it to go blank or appear. The closest you can be to the part in this example is 0.25, so I subtracted that value in order for it to be zero when you're standing on the part.
Hope this helps.
Houlardy