Making the BillboardGUI disappear when the mouse is removed

So I have this LocalScript that makes a BillboardGUI appear on a part when the mouse hovers over it.

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()  

UIS.InputChanged:Connect(function(input)
	if mouse.Target then
		if mouse.Target:FindFirstChild("Rarity") then
			if mouse.Target:FindFirstChild("Show") then
				mouse.Target.BillboardGui.Enabled = true
			else
				mouse.Target.BillboardGui.Enabled = false
			end
		end
	end
end)

How would I make it so the BillboardGUI vanishes when it’s no longer being hovered over? (By the client)

3 Likes

something like this should work

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()  

UIS.InputChanged:Connect(function(input)
	if mouse.Target then
		if mouse.Target:FindFirstChild("Rarity") then
			if mouse.Target:FindFirstChild("Show") then
				mouse.Target.BillboardGui.Enabled = true
				repeat task.wait() until (mouse.Target:FindFirstChild("Show") == nil)
				mouse.Target.BillboardGui.Enabled = false
			end
		end
	end
end)
1 Like

Well, the show thing doesn’t go away, so not exactly.

2 Likes

Correct code should be:

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()  

UIS.InputChanged:Connect(function(input)
	if mouse.Target then
		if mouse.Target:FindFirstChild("Rarity") then
			if mouse.Target:FindFirstChild("Show") then
				mouse.Target.BillboardGui.Enabled = true
                local targ = mouse.Target.BillboardGui
				repeat task.wait() until (mouse.Target ~= targ)
				targ.Enabled = false
			end
		end
	end
end)
3 Likes

Oh wow, this worked, but there’s a problem, the BbGUI only goes away if the mouse isn’t on another part with the Show value, because there are multiple parts with the Show value. Sorry.

No problem mate, keep scripting! oh, okay

Hopefully you see the edit I made

I edited the code, does this work now?

Well kinda, but the BillboardGUI flashes and then randomly goes away.

Can you send a reference video of this?

heres the video


sorry abt the quality and framerate (yes i know its bad)

Yeah I could see it but next time I recommend just using YouTube to upload an unlisted video.

Anyways.
Maybe this code works better:

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()  

UIS.InputChanged:Connect(function(input)
	if mouse.Target then
		if mouse.Target:FindFirstChild("Rarity") then
			if mouse.Target:FindFirstChild("Show") then
				mouse.Target.BillboardGui.Enabled = true
                local targ = mouse.Target
				repeat task.wait() until (mouse.Target ~= targ)
				targ.BillboardGui.Enabled = false
			end
		end
	end
end)

This works! Thanks (char limit kjdfhnbfxg iusdfxv)

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