Transparency value changes but text doesnt show up

Hello, this is my first topic I’m ever writing.
I am trying to make text show up after clicking a part by using a function and then calling it when needed, which shouldn’t be too hard but for me unfortunately it is.
Here is my code.

local tweenservice = game:GetService("TweenService")
local runservice = game:GetService("RunService")

local Gui = game:GetService("StarterGui"):WaitForChild("ItemInf")
local Text = Gui:WaitForChild("TextLabel")

----
local function ShowText()
	print("Showing Text")
	for i = 1,100 do
		
		
		Text.TextTransparency -=0.01
		wait(0.01)
	end
	for i = 1,30 do
		Text.BackgroundTransparency -=0.01
		wait(0.1)
	end
end

local function HideText()
	print("Hiding Text")
	for i = 1,70 do
		Text.BackgroundTransparency +=0.01
		wait(0.01)
	end
	for i = 1,100 do
		Text.TextTransparency +=0.01
		wait(0.01)
	end
end
----



local model = script.Parent

local cD = model.ClickDetector

local IsDisplaying = false

local highlight = Instance.new("Highlight")
highlight.Parent = model
highlight.OutlineTransparency = 1
highlight.FillTransparency = 1

cD.MouseHoverEnter:Connect(function()
	local goaltween = {}
	goaltween.OutlineTransparency = 0
	
	
	local tI = TweenInfo.new(0.5, Enum.EasingStyle.Quint)
	
	tweenservice:Create(highlight, tI, goaltween):Play()
end)

cD.MouseHoverLeave:Connect(function()
	local goaltween = {}
	goaltween.OutlineTransparency = 1
	
	local tI = TweenInfo.new(0.5, Enum.EasingStyle.Quint)

	tweenservice:Create(highlight, tI, goaltween):Play()
end)

cD.MouseClick:Connect(function()
	if IsDisplaying == false then
		ShowText()
		
	wait(8)
		HideText()
		IsDisplaying = false
	end
end)

The issue is that after i click my part when i check the GUI values I can see them changing the transparency to 0 but for some reason the text doesn’t show up.
I would greatly appreciate any help.

You’re getting the gui in StarterGui, not from the local player’s PlayerGui. StarterGui copies all the gui in it and gives it to players when they join (or when they respawn if ScreenGui.ResetOnSpawn is set to true). Since the player only sees the copied gui, they will not see the changes you make to StarterGui.

Try changing this line to
local Gui = game:GetService("Players").LocalPlayer:WaitForChild("ItemInf"),
or, if this script is a child of the gui, local Gui = script.Parent.
This will get the gui that the player actually sees, and then you can make changes to it.

Thank you very much for replying. I understand what you are trying to say and i did exactly that but for some reason the entire script broke and the part doesnt highlight anymore nor does the code print any messages. );

Thanks! I played around with the script and made it work!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.