How to make text show part name when hovering over part?

I used a script and wanted to make it so it shows text and updates it based on the part’s name, but it doesn’t seem to be working.

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local values = game.StarterGui.PartValues

mouse.Move:Connect(function()
	local target = mouse.Target

	for _,blocks in pairs(workspace.Blocks:GetChildren()) do
		if target == blocks then
			values.Id.TextTransparency = 0
			values.Id.PartName.Text = target.Name
		else
			values.Id.TextTransparency = 1
		end
	end
end)

This script is meant to make the text “id:” show with TextTransparency and then update the PartName TextLabel by getting the target name. Then if not selected, it keeps both TextLabels hidden.

(This is what it should look like when I select the part)

1 Like

Try this script?

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local values = game.StarterGui.PartValues

mouse.Move:Connect(function()
	local target = mouse.Target

	for _,blocks in pairs(workspace.Blocks:GetDescendants()) do
		if target == blocks then
			values.Id.TextTransparency = 0
			values.Id.PartName.Text = target.Name
		else
			values.Id.TextTransparency = 1
		end
	end
end)

mouse.Target could be a child of a model which is not what workspace.Blocks:GetChildren() gets

The cloned parts that go into “Blocks” (a folder) are just parts, no models in there.

I forgot that you can’t change the GUI by addressing it “game.StarterGui.PartValues” because game.StarterGui is just a folder that clone its descendants into player’s gui which means changing anything in this folder is basically useless.
Instead try :

local values = plr.PlayerGui.PartValues

image
You can only change GUI that inside Player Gui to make the changes visible to player, otherwise it will not.

It does redirect to the correct area now, it just doesn’t change the Transparency, nor update the text for any of the TextLabels.

Might be something wrong with the way I tried to make it update those values.

Can you show me your Gui and it’s descendants?

Screen Shot 2023-08-16 at 9.09.36 PM

Separate them from each other
and move your script to StarterGui

local values = game.StarterGui.PartValues

idk why but changing this line to

local values = script.Parent.PartValues

fixes the problem

The problem was fixed, but the text.Name part won’t disappear after hovering over it.

Making it do values.PartName.Text = nil doesn’t work either.

put after else PartName.Text = “”
or your default text like PartName.Text = “the name”

1 Like

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