✓ Accepted answer
I'd advise you to name your objects something that isn't very similar to common properties, such as "Name" and "Text". Name is a property of ALL DataModel objects in ROBLOX. Bad naming convention!
You also have to keep in mind that if you edit a GUI in StarterGui, it won't apply to any player before they respawn and get the updated GUI inserted into their PlayerGui. You want to change the GUI in the PlayerGui!
You can do this several ways, and I'll show you two of them.
The first is the use of player:GetMouse() and Mouse.Target to track what you're hovering your mouse over. This requires a LocalScript, but since you're editing GUIs you'd need that anyway.
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local target = game.Workspace["Apple Tree"]
local label = Player.PlayerGui.NameBox.NameGui.Text
Mouse.Move:connect(function()
if Mouse.Target and Mouse.Target:IsDescendantOf(target) then
label.Text = target.Name
else
label.Text = ""
end
end)
The second method is to actually use the ClickDetector. This requires the player to physically click on the tree, though - else the ClickDetector-event won't fire. I don't suggest using this method, as every player will require to bind the event.
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local target = game.Workspace["Apple Tree"]
local label = Player.PlayerGui.NameBox.NameGui.Text
target.ClickDetector.Clicked:connect(function())
label.Text = "Apple Tree"
end)
3 comments
RavenShield. This is hard to ask but can you make a script exactly like that except it is showing the players name when you hover over a player?
Wait. I can just switch a few things in the first script and get my script. Right?
That is very possible indeed, raystriker. Send me a message and I can help you there - or post an own question here and I'll assist you.