Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make billboard GUI show up WITH text on mouse hover?

Asked by 4 years ago
Edited by Azarth 4 years ago

This is my code.. How do I make the billboard GUI show up when I hover over the part? Also how do I make it not be half inside the part its parented to?

local computerScreen = game.Workspace.ComputerScreen

local CursorId = "2287179355"
local ClickDetector = Instance.new("ClickDetector")
ClickDetector.Parent = computerScreen
ClickDetector.MaxActivationDistance = 10
ClickDetector.CursorIcon = "rbxassetid://"..CursorId


local openGUI = Instance.new("BillboardGui")
openGUI.Parent = computerScreen
openGUI.Name = "OpenComputer"
openGUI.MaxDistance = 10
openGUI.Size = UDim2.new{1,0},{1,0}
openGUI.ExtentsOffset = Vector3.new(0,2,0)
openGUI.Enabled = false

local openText = Instance.new("TextLabel")
openText.Parent = computerScreen.OpenComputer
openText.Size = UDim2.new(28)
openText.Font = 10
openText.Text = "Open"
openText.Visible = false

ClickDetector.MouseHoverEnter:Connect(function()
    openGUI.Enabled = true
    openText.Visible = true
    print("Done")
end)

ClickDetector.MouseHoverLeave:Connect(function()
    openGUI.Enabled = false
    openText.Visible = false
    print("Done Left")
end)

0
REFRESH FOR EIDT CoreMcNugget 15 — 4y
0
Edit* CoreMcNugget 15 — 4y

2 answers

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You mostly had it, but there are a few things to note here.

  1. You need to set a GUIs Size and Position like so UDim2.new(0,0,0,0), without curly braces.
  2. Set the Parent of an object after you're done setting its properties.
  3. You need to set the Adornee of the part
  4. FontSize is the correct property for scaling, not Font.
  5. Enabling and Disabling the GUI doesn't serve a purpose here.
  6. AlwaysOnTop will make the GUI stay on top of objects.
local computerScreen = game.Workspace:WaitForChild("ComputerScreen")
local CursorId = "2287179355"
local ClickDetector = Instance.new("ClickDetector")
ClickDetector.MaxActivationDistance = 10
ClickDetector.CursorIcon = "rbxassetid://"..CursorId
-- Parent after you're done setting properties
ClickDetector.Parent = computerScreen



local openGUI = Instance.new("BillboardGui")
-- AlwaysOnTop puts GUI on top of everything.
openGUI.AlwaysOnTop = true
openGUI.Name = "OpenComputer"
-- Set Adornee to computerScreen
openGUI.Adornee = computerScreen
openGUI.MaxDistance = 10
-- Don't use brackets
openGUI.Size = UDim2.new(1,0,1,0)
openGUI.ExtentsOffset = Vector3.new(0,2,0)
-- Parent after you're done setting properties
openGUI.Parent = computerScreen


local openText = Instance.new("TextLabel")
-- FontSize 7 = 24
openText.FontSize = 7
-- Set Size of TextLabel
openText.Size = UDim2.new(1,0,1,0)
openText.Font = 10
openText.Text = "Open"
openText.Visible = false
-- Parent after you're done setting properties
openText.Parent = computerScreen.OpenComputer


ClickDetector.MouseHoverEnter:Connect(function()
    openText.Visible = true
    print("Done")
end)

ClickDetector.MouseHoverLeave:Connect(function()
    openText.Visible = false
    print("Done Left")
end)

0
BillBoard GUI still not showing CoreMcNugget 15 — 4y
0
Edited, try again Azarth 3141 — 4y
0
Working. Thanks! CoreMcNugget 15 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Add a ClickDetector into the part and then insert this into the part:

ClickDetect = script.Parent.ClickDetector
Billboard = script.Parent.BillboardGui
--make sure to add a BillboardGui with a TextLabel in it in the part.
--And add a ClickDetector in the part, too.
Billboard.TextLabel.Visible = false

ClickDetect.MouseHoverEnter:connect(function()
     Billboard.TextLabel.Visible = true
end)

If you want to make it disappear when exit, put what's above in with the following:

ClickDetect.MouseHoverLeave:connect(function()
     Billboard.TextLabel.Visible = false
end)

Answer this question