Mouse.Target Not Printing On TextLabel

Hello, So I am working on just some scripting practice, and my issue is basically I have a script that when the mousebutton2 is pressed down it will print what the mouse is hovering over, but it wont print,. but I have tried several things and looked at several ways to fix my issue, here is my script

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local TextLabel = game.StarterGui.ObjectNamer.Frame.TextLabel
Mouse.Button1Down:Connect(function()
	print("You Clicked Your Mouse!!")
end)


Mouse.Button2Down:Connect(function()
	print(Mouse.Target.Name)
	TextLabel.Text = Mouse.Target.Name
	game.Players.LocalPlayer.PlayerGui.ObjectNamer.Frame.Visible = true
end)

On line 3, youre defining the gui object in starter GUI. This is a universal version of the GUI that gets cloned into each player upon initialization. If you want your GUI to show something, you must access it through game.Players.LocalPlayer.PlayerGui... Let me know if this makes sense.

I redid the code to fit what you said, but now I get a error that says tihs * ObjectNamer is not a valid member of PlayerGui “Players.Kevblx.PlayerGui”* Here is the script and a screenshot of the gui order

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local TextLabel =  game.Players.LocalPlayer.PlayerGui.ObjectNamer.Frame.TextLabel
Mouse.Button1Down:Connect(function()
	print("You Clicked Your Mouse!!")
end)


Mouse.Button2Down:Connect(function()
	print(Mouse.Target.Name)
	TextLabel.Text = Mouse.Target.Name
	game.Players.LocalPlayer.PlayerGui.ObjectNamer.Frame.Visible = false
end)

image

Is the loadcharacter property of players enabled?

Yep, I don’t mess with those settings.

Would a copy Help? It usually works if people look at a copy.

Try using :WaitForChild() instead. If that doesnt work, test your game and look if it is actually there in the explorer

WaitForChild Where in The Script?

Instead of playergui.child do playergui:WaitForChild(“child”)

local TextLabel = player.PlayerGui:WaitForChild("ObjectName").Frame.TextLabel

Now it works, thanks so much! I marked your answer as solution!

1 Like