Unable to make GUI appear after touching a part

Hello,
I want to make this GUI visible again (right now it’s visible as soon as the player joins the game) when a part is touched and I have this LocalScript:

local part = game.Workspace.TouchPart;
local plr = game.Players.LocalPlayer;
local ui = script.Parent;

part.Touched:Connect(function(hit)
	if plr.Character ~= nil and hit.Parent == plr.Character then
		ui.Visible = true; 
	end 
end)

and this is the structure:
image

LocalScript content (the one inside UIGradient) in case it’s needed:

task.wait(3)

game.TweenService:Create(script.Parent, TweenInfo.new(1), {Offset = Vector2.new(1, 0)}):Play()

task.wait(3)

script.Parent.Offset = Vector2.new(-1, 0)

script.Parent.Transparency = NumberSequence.new({
	NumberSequenceKeypoint.new(0, 1),
	NumberSequenceKeypoint.new(1, 0)
})

game.TweenService:Create(script.Parent, TweenInfo.new(1), {Offset = Vector2.new(1, 0)}):Play()
task.wait(2)
game.TweenService:Create(script.Parent.Parent.Parent, TweenInfo.new(1.5), {BackgroundTransparency = 1}):Play()

how can I make the GUI appear again (it’s always set on visible because it starts as soon as the player joins) when the part is touched?

Thanks in advance

Just want to clarify something quick, so are you asking to make it so this GUI Is not visible when they join?

I want the GUI to stay visible when the players join the game and when they touch the part

Okay and do they close the Ui, if they don’t and its always visible and on their screen, what is the need to make something that is already visible, visible with the part?

Correct me if I’m understanding wrong.

The GUI disappears on their screen automatically after the animation is done

1 Like

How are you making it disappear?

task.wait(3)

game.TweenService:Create(script.Parent, TweenInfo.new(1), {Offset = Vector2.new(1, 0)}):Play()

task.wait(3)

script.Parent.Offset = Vector2.new(-1, 0)

script.Parent.Transparency = NumberSequence.new({
	NumberSequenceKeypoint.new(0, 1),
	NumberSequenceKeypoint.new(1, 0)
})

game.TweenService:Create(script.Parent, TweenInfo.new(1), {Offset = Vector2.new(1, 0)}):Play()
task.wait(2)
game.TweenService:Create(script.Parent.Parent.Parent, TweenInfo.new(1.5), {BackgroundTransparency = 1}):Play()

Okay so, the Ui isn’t showing up, because its transparent. Trying to turn visible true again won’t do anything because it is still visible its just transparent. Personally after turning it transparent, I’d turn it invisible, and have it so that when they touch the part it resets the Ui to its original state.

How would I fix that in this script? I haven’t understood really well how to do it

local part = game.Workspace.TouchPart;
local plr = game.Players.LocalPlayer;
local ui = script.Parent;

part.Touched:Connect(function(hit)
	if plr.Character ~= nil and hit.Parent == plr.Character then
		ui.Visible = true; 
	end 
end)

Okay so currently, your UIGradient script is just turning your UI transparent, so in the properties of your UI Visible = true, however the Transparency of your Frame(Frame that is the child of the ScreenGui) is equal to 1, meaning that your ScreenGui is Visible, however the Frame is not.

What you need to do is after it’s transparent, remove its visibility, and then turn the background back to 0. That’s the simple way to fix it.

local part = game.Workspace.TouchPart
local plr = game.Players.LocalPlayer
local ui = script.Parent

part.Touched:Connect(function()
	ui.Visible = true
end)
--- if you want to check the player
part.Touched:Connect(function(hit)
	if plr.Character ~= nil and hit.Parent.Name == plr.Name then
		ui.Visible = true 
	end 
end)

I don’t know what the “;” does but I’ve never seen nor used it before.

1 Like