Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can anyone help me with this gui?

Name = game.StarterGui.NameBox.NameGUI.Text

Name.Text = "Apple Tree"

Name.Text = ""

so i have a Screen GUI that i called "NameBox" with a Frame inside it called "NameGui" and inside the Frame i have a TextLabel named "Text". I have a model called "Apple Tree". What I want this script to do is when I hover over the Apple tree (The apple tree has a click detector in it) the name appears in the Frame. how do i do this?

2 answers

✓ 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()
-- Checking if the target actually exists, and checks if the target is a descendant (child, direct or indirect) of our 'target'
    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

0

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?

0

Wait. I can just switch a few things in the first script and get my script. Right?

0

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.

Well first of all, you don't want to use a ClickDetector. You should use Mouse.Target to do this. You would need a LocalScript inside the TextLabel. Insert this code:

local Mouse=game.Players.LocalPlayer:GetMouse() --Gets the players Mouse
function Mouse.Move:connect(function(Property) --Fires each time a property of the Mouse is changed
		if game.Workspace.AppleTree:FindFirstChild(Mouse.Target)~=nil then --Checks if the Mouse is hovering over the target or not (You may need to adjust this to fit the apple trees actual name...whatever it is)
			script.Parent.Visible=true --shows text if Mouse is over tree
		else
			script.Parent.Visible=false --removes text if Mouse isn't over tree
		end
	end
end)

If you have any further questions or complications, leave a comment below addressing the issue. Hope I helped :P

This discussion is preserved as it was. New answers, comments, and votes are closed.