Tricky Tooltip Question

Hi there, I have having a tricky problem handling the process of giving a highlight and showing tooltip information on a player.

What’s happening in game:
On your first time moving your mouse over a player you can see their name. But also if I hover over the hair on the player, its thinking that the hair is the person too and its pulling up real information about a player with the item name. It’s not supposed to do that. (And also only happens once, and after you unhover and rehover, it won’t do that again till you reset.)

What I want to happen:
No matter if you’re hovering over their body parts or hats/hairs you’re only supposed to see the players name no matter what.

Below is the setup, script and a GIF of what’s happening.

image

--27 Lines of Locals (can see upon request)

--GetUserIDFromName function (can see upon request)

--UpdateTooltipPosition function (can see upon request)

local function CreateHighlight(Target)
	if not Target:FindFirstChildWhichIsA("Highlight") then
		local NewHighlight = Instance.new("Highlight")
		NewHighlight.DepthMode = Enum.HighlightDepthMode.Occluded
		NewHighlight.FillTransparency = 1
		NewHighlight.OutlineTransparency = 1
		NewHighlight.Parent = Target
		NewHighlight.Name = Target.Name.."Highlight"
		return NewHighlight
	end
end

local function FadeHighlight(Highlight, FadeIn)
	if Highlight == nil then return end
	local Goal = FadeIn and {OutlineTransparency = 0} or {OutlineTransparency = 1}
	local Tween = TweenService:Create(Highlight, TweenInfo.new(0.5), Goal)
	Tween:Play()
	warn("Applied Highlight")
end

local function FadeOutAndDestroy(Highlight)
	if Highlight and Highlight.Parent then
		Highlight:Destroy()
		warn("Deleted Highlight")
	end
end

--CheckClothes function (can see upon request)

local function UpdateTooltip()
	local Target = Mouse.Target
	UpdateTooltipPosition()
	local IsWithinCameraMagnitude = (Head.CFrame.Position - Camera.CFrame.Position).Magnitude < CameraMagnitude
	
	if Target and Target.Parent then
		local IsHighlightedItem = false
		for _, Tags in pairs(HighlightItemsModule) do
			for _, TaggedItem in pairs(CollectionService:GetTagged(Tags)) do
				if TaggedItem == Target.Parent then
					IsHighlightedItem = true
					break
				end
			end
		end
		
		if IsHighlightedItem or Target.Parent:IsA("Model") and Target.Parent.Parent == game.Workspace or Target.Parent.Parent:IsA("Model") and Target.Parent.Parent.Parent == game.Workspace then
			--Handling cafe items highlights (can see upon request)
		end
		
		--[[BELOW IS THE CODE I BELIEVE IS CUASING THE PROBLEM]]
		
		--if IsWithinCameraMagnitude and PlayerIsInGroup and not DestroyScript and Target.Parent:IsA("Model") and Target.Parent.Parent == game.Workspace and not Target.Parent:FindFirstChildWhichIsA("Highlight") then
		if IsWithinCameraMagnitude and PlayerIsInGroup and not DestroyScript and ((Target.Parent:IsA("Model") and Target.Parent.Parent == game.Workspace) or (Target.Parent.Parent:IsA("Model") and Target.Parent.Parent.Parent == game.Workspace)) and not (Target.Parent:FindFirstChildWhichIsA("Highlight") or Target.Parent.Parent:FindFirstChildWhichIsA("Highlight")) then
			print("Check - A")
			DetectedNamesUserID = GetUserIDFromName(Target.Parent.Name)
			if DetectedNamesUserID then
				RealPlayersName = Players:GetNameFromUserIdAsync(DetectedNamesUserID)
				local NewHighlight = CreateHighlight(Target.Parent)
				PlayerInformation.Text = "@"..RealPlayersName.." ("..DetectedNamesUserID..")"
				PlayerInformationSelectText.Text = "Cmd/Ctrl + Right Click to Select"
				FadeHighlight(NewHighlight, true)
				print("Player")
			end
		end
		
		for _, Model in pairs(game.Workspace:GetDescendants()) do
			if Model:IsA("Model") and Model.Name ~= Target.Parent.Name or (Head.CFrame.Position - Camera.CFrame.Position).Magnitude > CameraMagnitude then
				--if Model:IsA("Model") and (Model.Name ~= Target.Parent.Name or Model.Parent.Parent.Name ~= Target.Parent.Parent.Name or (Head.CFrame.Position - Camera.CFrame.Position).Magnitude > CameraMagnitude) then
				for _, ModelHighlight in pairs(Model:GetChildren()) do
					if ModelHighlight:IsA("Highlight") then
						print("Check - B [Deleted]")
						ItemTooltip.Text = ""
						PlayerInformation.Text = ""
						PlayerInformationSelectText.Text = ""
						RealPlayersName = ""
						UserIDBox.Text = ""
						UserIDBoxSelectText.Text = ""
						DetectedNamesUserID = 0
						FadeOutAndDestroy(ModelHighlight)
					end
				end
			end
		end
	end
end

--Code to handle LeftControl & MouseButton2 inputs (can see upon request)

--Code to handle LeftControl & C KeyCode input (can see upon request)

RunService.RenderStepped:Connect(UpdateTooltip)

38778de3bfcb4decd9651a9ff4348f94

2 Likes

I suspect it’s where you think it is too. However, there is a function you are using that you don’t supply. I assume the error is a mix between those 2.

I might be able to fix it anyways or at least point out what may be going wrong. Your code seems to at least be somewhat aware of this

image
The handle under MadScientistHair. You have some checks that are in place that seem to want to conditionally handle it when something like that happens. That makes sense, but now you are needing to track multiple things. Here is my proposal for a new section.

local function handleHighlight(Target)
    local maybeCharacter = Target:FindFirstAncestorOfClass("Model")

    if isWithinCameraMagnitude then return end
    if DestroyScript then return end
    if not maybeCharacter then return end
    if maybeCharacter.Parent ~= game.Workspace then return end
    if maybeCharacter.Parent:FindFirstChildWhichIsA("Highlight") then return end

    if not game.Players:GetPlayerFromCharacter(maybeCharacter) then return end --This should handle making sure it's a player and not an NPC.  You seem to care about that, this might be simpler.  remove this line if you want NPCs included
    print("guard clauses passed")
    local character = maybeCharacter --Just removing uncertainty so it's clear that you know this is a character now
    
    DetectedNamesUserID = GetUserIDFromName(character.Name)
    if DetectedNamesUserID then
		RealPlayersName = Players:GetNameFromUserIdAsync(DetectedNamesUserID)
		local NewHighlight = CreateHighlight(character)
		PlayerInformation.Text = "@"..RealPlayersName.." ("..DetectedNamesUserID..")"
		PlayerInformationSelectText.Text = "Cmd/Ctrl + Right Click to Select"
		FadeHighlight(NewHighlight, true)
		print("Player")
	end
end

So put that function in your code and replace

This part
if IsWithinCameraMagnitude and PlayerIsInGroup and not DestroyScript and ((Target.Parent:IsA("Model") and Target.Parent.Parent == game.Workspace) or (Target.Parent.Parent:IsA("Model") and Target.Parent.Parent.Parent == game.Workspace)) and not (Target.Parent:FindFirstChildWhichIsA("Highlight") or Target.Parent.Parent:FindFirstChildWhichIsA("Highlight")) then
			print("Check - A")
			DetectedNamesUserID = GetUserIDFromName(Target.Parent.Name)
			if DetectedNamesUserID then
				RealPlayersName = Players:GetNameFromUserIdAsync(DetectedNamesUserID)
				local NewHighlight = CreateHighlight(Target.Parent)
				PlayerInformation.Text = "@"..RealPlayersName.." ("..DetectedNamesUserID..")"
				PlayerInformationSelectText.Text = "Cmd/Ctrl + Right Click to Select"
				FadeHighlight(NewHighlight, true)
				print("Player")
			end
		end

with a call to handleHighlight(Target) or whatever you want to call it. I put it in a function so I could use guard clauses to avoid that giant complicated if statement you have since it’s hard to read.

This should ensure that only a real players character gets passed to whatever function you have.

1 Like

I copied and pasted your code into my script below the CheckClothes() function, (just to check if cafe employee wearing clothes for another portion of the code which is unrelated) and took out 2 checks.

Then down below this is what my script looks like.

And this is what happens in game.
727aedfb178d65abd246e4427ea2ba02

Any thoughts on what’s happening? I’m a little confused.

In the function that you’re using to get the 3D position of the player’s mouse, you can check to see if the BasePart that was hit is a descendant of an Accessory, and if so, check the Accessory’s AccessoryType to see if it’s hair:

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Workspace = game:GetService("Workspace")

local DISTANCE = 1024

local camera = Workspace.CurrentCamera or Workspace:WaitForChild("Camera")


local function getPlayer(): Player?
	local mouseLocation = UserInputService:GetMouseLocation()
	local ray = camera:ViewportPointToRay(mouseLocation.X, mouseLocation.Y)
	local raycastResult = Workspace:Raycast(ray.Origin, ray.Direction * DISTANCE)

	if raycastResult then
		local accessory = raycastResult.Instance:FindFirstAncestorOfClass("Accessory")

		if
			accessory
			and accessory.AccessoryType == Enum.AccessoryType.Hair
		then
			return
		end

		local model = raycastResult.Instance:FindFirstAncestorOfClass("Model")

		if model then
			return Players:GetPlayerFromCharacter(model)
		end
	end
end

RunService.RenderStepped:Connect(function()
	local player = getPlayer()

	if player then
		print(player.DisplayName)
	end
end)

I’ve written a function to find the character from any part, and returns null if its not a descendant of a character.

Give this a shot and let me know how it goes.

local locateCharacter(inst)
	if game.Players:GetPlayerFromCharacter(inst.Parent) then return inst.Parent; end
	for i,v in pairs(game.Players:GetChildren()) do
		if not v.Character then return; end
		local Character = inst:FindFirstAncestor(v.Character)
		if Character then return Character; end
	end
end

local Character = locateCharacter(Target)
if IsWithinCameraMagnitude and PlayerIsInGroup and not DestroyScript and Character then
	print("Check - A")
	DetectedNamesUserID = GetUserIDFromName(Character.Name)
	if DetectedNamesUserID then
		RealPlayersName = Players:GetNameFromUserIdAsync(DetectedNamesUserID)
		local NewHighlight = CreateHighlight(Character)
		PlayerInformation.Text = "@"..RealPlayersName.." ("..DetectedNamesUserID..")"
		PlayerInformationSelectText.Text = "Cmd/Ctrl + Right Click to Select"
		FadeHighlight(NewHighlight, true)
		print("Player")
	end
end

for _, Model in pairs(game.Workspace:GetDescendants()) do
	if Model:IsA("Model") and Model.Name ~= Character.Name or (Head.CFrame.Position - Camera.CFrame.Position).Magnitude > CameraMagnitude then
		for _, ModelHighlight in pairs(Model:GetChildren()) do
			if ModelHighlight:IsA("Highlight") then
				print("Check - B [Deleted]")
				ItemTooltip.Text = ""
				PlayerInformation.Text = ""
				PlayerInformationSelectText.Text = ""
				RealPlayersName = ""
				UserIDBox.Text = ""
				UserIDBoxSelectText.Text = ""
				DetectedNamesUserID = 0
				FadeOutAndDestroy(ModelHighlight)
			end
		end
	end
end

My guess is you are not getting a return from GetUserIDFromName(character.Name).

I recommend printing character:GetFullName() after the guard clauses (and after it’s been defined) to check that it is getting the player like you expect.

I might recommend doing game.Players:GetPlayerFromCharacter(character).UserID instead (not sure if the property is actually called userID and don’t have time to check rn)

Hi there, thanks for the response.

Are you referring to my UpdateTooltipPosition function?
The contents of it looks like this:

local function UpdateTooltipPosition()
	ItemTooltip.Position = UDim2.new(0, Mouse.X + 16, 0, Mouse.Y + 55)
	PlayerInformation.Position = UDim2.new(0, Mouse.X + 16, 0, Mouse.Y + 55)
	UserIDBox.Position = UDim2.new(0, Mouse.X + 16, 0, Mouse.Y + 55)
end

Thanks so much for the piece of code you provided. Unfortunately, I am just a little confused on where I should be putting this code exactly. I try to work on this my own before asking such a per say, ‘dumb’ question, but my apologies.

1 Like

This sadly didn’t work even with tweaks that I was making and about 30 minutes of messing around with it.

@tlr22 @JohhnyLegoKing @Siydge and others:
Here is my raw, full script. Not trying to gatekeep it but I believe that the rest of it might be important yet a little confusing. I was trying to stay simple but, that’s not how this is going, so I’m sorry!

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
local MarketplaceService = game:GetService("MarketplaceService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local GameDataModule = require(game.ReplicatedStorage.Modules.GameDataModule)
local RankDataModule = require(game.ReplicatedStorage.Modules.RankDataModule)
local HighlightItemsModule = require(game.ReplicatedStorage.Modules.HighlightItemsModule)
local ItemTooltip = script.Parent.ItemTooltip
local PlayerInformation = script.Parent.PlayerInformation
local PlayerInformationSelectText = script.Parent.PlayerInformation.SelectText
local UserIDBox = script.Parent.UserID
local UserIDBoxSelectText = script.Parent.UserID.SelectText
local ItemMagnitude = GameDataModule.ItemMagnitude
local CameraMagnitude = GameDataModule.CameraMagnitude
local Camera = game.Workspace.CurrentCamera
local Mouse = LocalPlayer:GetMouse()
local DestroyScript = LocalPlayer:GetRankInGroup(GameDataModule.GroupID) <= RankDataModule.Trainee
local Employee = LocalPlayer:GetRankInGroup(GameDataModule.GroupID) >= RankDataModule.JuniorBarista
local HasPremium = MarketplaceService:UserOwnsGamePassAsync(LocalPlayer.UserId, GameDataModule.Gamepass_Premium)
local PlayerIsInGroup = LocalPlayer:IsInGroup(GameDataModule.GroupID)
local RealPlayersName = ""
local DetectedNamesUserID = 0

local function GetUserIDFromName(Name)
	local UserID
	local Success = pcall(function()
		UserID = Players:GetUserIdFromNameAsync(Name)
	end)
	return Success and UserID or nil
end

local function UpdateTooltipPosition()
	ItemTooltip.Position = UDim2.new(0, Mouse.X + 16, 0, Mouse.Y + 55)
	PlayerInformation.Position = UDim2.new(0, Mouse.X + 16, 0, Mouse.Y + 55)
	UserIDBox.Position = UDim2.new(0, Mouse.X + 16, 0, Mouse.Y + 55)
end

local function CreateHighlight(Target)
	if not Target:FindFirstChildWhichIsA("Highlight") then
		local NewHighlight = Instance.new("Highlight")
		NewHighlight.DepthMode = Enum.HighlightDepthMode.Occluded
		NewHighlight.FillTransparency = 1
		NewHighlight.OutlineTransparency = 1
		NewHighlight.Parent = Target
		NewHighlight.Name = Target.Name.."Highlight"
		return NewHighlight
	end
end

local function FadeHighlight(Highlight, FadeIn)
	if Highlight == nil then return end
	local Goal = FadeIn and {OutlineTransparency = 0} or {OutlineTransparency = 1}
	local Tween = TweenService:Create(Highlight, TweenInfo.new(0.5), Goal)
	Tween:Play()
	warn("Applied Highlight")
end

local function FadeOutAndDestroy(Highlight)
	if Highlight and Highlight.Parent then
		Highlight:Destroy()
		warn("Deleted Highlight")
	end
end

local function CheckClothes(PlayerName)
	local Shirt = game.Workspace[PlayerName]:FindFirstChild("Shirt")
	local Pants = game.Workspace[PlayerName]:FindFirstChild("Pants")
	if Shirt.ShirtTemplate == "http://www.roblox.com/asset/?id=11755741005" or Shirt.ShirtTemplate == "http://www.roblox.com/asset/?id=11755704892" or Shirt.ShirtTemplate == "http://www.roblox.com/asset/?id=11781401446" or Shirt.ShirtTemplate == "http://www.roblox.com/asset/?id=11781395691" and Pants.PantsTemplate == "http://www.roblox.com/asset/?id=11761863905" or Pants.PantsTemplate == "http://www.roblox.com/asset/?id=11755633591" or Pants.PantsTemplate == "http://www.roblox.com/asset/?id=11762009076" or Pants.PantsTemplate == "http://www.roblox.com/asset/?id=11762008361" then
		return true
	else
		return false
	end
end

local function UpdateTooltip()
	local Target = Mouse.Target
	UpdateTooltipPosition()
	local IsWithinCameraMagnitude = (Head.CFrame.Position - Camera.CFrame.Position).Magnitude < CameraMagnitude
	
	if Target and Target.Parent then
		local IsHighlightedItem = false
		for _, Tags in pairs(HighlightItemsModule) do
			for _, TaggedItem in pairs(CollectionService:GetTagged(Tags)) do
				if TaggedItem == Target.Parent then
					IsHighlightedItem = true
					break
				end
			end
		end
		
		if IsHighlightedItem or Target.Parent:IsA("Model") and Target.Parent.Parent == game.Workspace or Target.Parent.Parent:IsA("Model") and Target.Parent.Parent.Parent == game.Workspace then
			local KitchenTrashcanAttribute = Target.Parent:GetAttribute("KitchenTrashcan")
			local PremiumTrashcanAttribute = Target.Parent:GetAttribute("PremiumTrashcan")
			local IsTrashcan = string.sub(Target.Parent.Name, 1, #"Trashcan") == "Trashcan"
			local HasUniform = CheckClothes(LocalPlayer.Name)
			local IsWithinItemMagnitude = nil
			if IsHighlightedItem and Target.Parent.Hitbox then
				IsWithinItemMagnitude = (Head.Position - Target.Parent.Hitbox.Position).Magnitude < ItemMagnitude
			end
			
			if IsTrashcan and not KitchenTrashcanAttribute and not PremiumTrashcanAttribute and IsWithinItemMagnitude and IsWithinCameraMagnitude then
				ItemTooltip.Text = Target.Parent:GetAttribute("ItemName") or ""
				if not Target.Parent:FindFirstChild(Target.Parent.Name.."Highlight") then
					local NewHighlight = CreateHighlight(Target.Parent)
					FadeHighlight(NewHighlight, true)
				end
			elseif Employee and IsWithinItemMagnitude and IsWithinCameraMagnitude and (Target.Parent.Parent.Parent.Name == "Kitchen" or Target.Parent.Parent.Parent.Parent.Name == "Kitchen") and HasUniform then
				ItemTooltip.Text = Target.Parent:GetAttribute("ItemName") or ""
				if not Target.Parent:FindFirstChild(Target.Parent.Name.."Highlight") then
					local NewHighlight = CreateHighlight(Target.Parent)
					FadeHighlight(NewHighlight, true)
				end
			elseif Employee and IsWithinItemMagnitude and IsWithinCameraMagnitude and (Target.Parent.Parent.Parent.Name == "BaristaLounge" or Target.Parent.Parent.Parent.Parent.Name == "BaristaLounge") then
				ItemTooltip.Text = Target.Parent:GetAttribute("ItemName") or ""
				if not Target.Parent:FindFirstChild(Target.Parent.Name.."Highlight") then
					local NewHighlight = CreateHighlight(Target.Parent)
					FadeHighlight(NewHighlight, true)
				end
			elseif HasPremium and Target.Parent.Name == "Trashcan7" and IsWithinItemMagnitude and IsWithinCameraMagnitude then
				ItemTooltip.Text = Target.Parent:GetAttribute("ItemName") or ""
				if not Target.Parent:FindFirstChild(Target.Parent.Name.."Highlight") then
					local NewHighlight = CreateHighlight(Target.Parent)
					FadeHighlight(NewHighlight, true)
				end
			end
		end
		
		--if IsWithinCameraMagnitude and PlayerIsInGroup and not DestroyScript and Target.Parent:IsA("Model") and Target.Parent.Parent == game.Workspace and not Target.Parent:FindFirstChildWhichIsA("Highlight") then
		if IsWithinCameraMagnitude and PlayerIsInGroup and not DestroyScript and ((Target.Parent:IsA("Model") and Target.Parent.Parent == game.Workspace) or (Target.Parent.Parent:IsA("Model") and Target.Parent.Parent.Parent == game.Workspace)) and not (Target.Parent:FindFirstChildWhichIsA("Highlight") or Target.Parent.Parent:FindFirstChildWhichIsA("Highlight")) then
			print("Check - A")
			DetectedNamesUserID = GetUserIDFromName(Target.Parent.Name)
			if DetectedNamesUserID then
				RealPlayersName = Players:GetNameFromUserIdAsync(DetectedNamesUserID)
				local NewHighlight = CreateHighlight(Target.Parent)
				PlayerInformation.Text = "@"..RealPlayersName.." ("..DetectedNamesUserID..")"
				PlayerInformationSelectText.Text = "Cmd/Ctrl + Right Click to Select"
				FadeHighlight(NewHighlight, true)
				print("Player")
			end
		end
		
		for _, Model in pairs(game.Workspace:GetDescendants()) do
			if Model:IsA("Model") and Model.Name ~= Target.Parent.Name or (Head.CFrame.Position - Camera.CFrame.Position).Magnitude > CameraMagnitude then
			--if Model:IsA("Model") and (Model.Name ~= Target.Parent.Name or Model.Parent.Parent.Name ~= Target.Parent.Parent.Name or (Head.CFrame.Position - Camera.CFrame.Position).Magnitude > CameraMagnitude) then
				for _, ModelHighlight in pairs(Model:GetChildren()) do
					if ModelHighlight:IsA("Highlight") then
						print("Check - B [Deleted]")
						ItemTooltip.Text = ""
						PlayerInformation.Text = ""
						PlayerInformationSelectText.Text = ""
						RealPlayersName = ""
						UserIDBox.Text = ""
						UserIDBoxSelectText.Text = ""
						DetectedNamesUserID = 0
						FadeOutAndDestroy(ModelHighlight)
					end
				end
			end
		end
	end
end

UserInputService.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.LeftControl then
		UserInputService.InputBegan:Connect(function(InputedObject)
			if InputedObject.UserInputType == Enum.UserInputType.MouseButton2 then
				if Mouse.Target and Mouse.Target.Parent:IsA("Model") and Mouse.Target.Parent.Parent == game.Workspace then
					PlayerInformation.Text = ""
					PlayerInformationSelectText.Text = ""
					UserIDBox.Text = "@"..RealPlayersName.." ("..DetectedNamesUserID..")"
					UserIDBoxSelectText.Text = "Cmd/Ctrl + C to Copy User ID"
					UserIDBox:CaptureFocus()
					UserIDBox.SelectionStart = 0
					UserIDBox.CursorPosition = #UserIDBox.Text + 1
					UserIDBox.Visible = true
				end
			end
		end)
	end
end)

UserInputService.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.LeftControl then
		UserInputService.InputBegan:Connect(function(InputedObject)
			if InputedObject.KeyCode == Enum.KeyCode.C and UserIDBoxSelectText.Text == "Cmd/Ctrl + C to Copy User ID" then
				UserIDBoxSelectText.Text = "Copied player information"
				wait(2)
				if UserIDBoxSelectText.Text ~= "Cmd/Ctrl + C to Copy User ID" then
					UserIDBox.Visible = false
					UserIDBox.Text = ""
					UserIDBoxSelectText.Text = ""
					PlayerInformation.Text = "@"..RealPlayersName.." ("..DetectedNamesUserID..")"
					PlayerInformationSelectText.Text = "Cmd/Ctrl + Right Click to Select"
				end
			end
		end)
	end
end)

RunService.RenderStepped:Connect(UpdateTooltip)

But @Siydge I kept running into a few errors yet this was my most common one even though I feel like I had addressed the problem.

1 Like

It’s meant to be a replacement for the Mouse instance returned by LocalPlayer:GetMouse()

The getPlayer function will return nil if you hover your mouse over a player’s hair, but it’s able to detect the player if you hover over the rest of their character

If a player is found you can then run the code to display the tooltip GUI, although for positioning the GUI you’ll need to modify the function so that it returns the mouseLocation as well (I should be able to do it for you later today if you experience any difficulties)


@ThinkingAIINight

I’ve prepared this place file which shows a working version of what I was talking about:

TooltipGuiExample.rbxl (58.8 KB)

All the scripts are found inside the PlayerInfoGui that’s inside StarterGui

1 Like

Sorry for the really late reply, got busy!

So I was in the place file that you sent me (thank you so much) and I was trying to implement your code into mine and this is what I have so far. I tried to make it known what was new and old and or original.

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
local MarketplaceService = game:GetService("MarketplaceService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local GameDataModule = require(game.ReplicatedStorage.Modules.GameDataModule)
local RankDataModule = require(game.ReplicatedStorage.Modules.RankDataModule)
local HighlightItemsModule = require(game.ReplicatedStorage.Modules.HighlightItemsModule)
local ItemTooltip = script.Parent.ItemTooltip
local PlayerInformation = script.Parent.PlayerInformation
local PlayerInformationSelectText = script.Parent.PlayerInformation.SelectText
local UserIDBox = script.Parent.UserID
local UserIDBoxSelectText = script.Parent.UserID.SelectText
local ItemMagnitude = GameDataModule.ItemMagnitude
local CameraMagnitude = GameDataModule.CameraMagnitude
local Camera = game.Workspace.CurrentCamera
local Mouse = LocalPlayer:GetMouse()
local DestroyScript = LocalPlayer:GetRankInGroup(GameDataModule.GroupID) <= RankDataModule.Trainee
local Employee = LocalPlayer:GetRankInGroup(GameDataModule.GroupID) >= RankDataModule.JuniorBarista
local HasPremium = MarketplaceService:UserOwnsGamePassAsync(LocalPlayer.UserId, GameDataModule.Gamepass_Premium)
local PlayerIsInGroup = LocalPlayer:IsInGroup(GameDataModule.GroupID)
local RealPlayersName = ""
local DetectedNamesUserID = 0

local RaycastParameters --[[New]]
local GetMouseData = require(script:WaitForChild("MouseData")) --[[New]]
local Thread --[[New]]
local FormatText = "<b>@%s (%d)</b>\nCmd/Ctrl + Right Click to Select" --[[New]]

local function GetUserIDFromName(Name)
	local UserID
	local Success = pcall(function()
		UserID = Players:GetUserIdFromNameAsync(Name)
	end)
	return Success and UserID or nil
end

local function UpdateTooltipPosition()
	ItemTooltip.Position = UDim2.new(0, Mouse.X + 16, 0, Mouse.Y + 55)
	PlayerInformation.Position = UDim2.new(0, Mouse.X + 16, 0, Mouse.Y + 55)
	UserIDBox.Position = UDim2.new(0, Mouse.X + 16, 0, Mouse.Y + 55)
end

local function CreateHighlight(Target)
	if not Target:FindFirstChildWhichIsA("Highlight") then
		local NewHighlight = Instance.new("Highlight")
		NewHighlight.DepthMode = Enum.HighlightDepthMode.Occluded
		NewHighlight.FillTransparency = 1
		NewHighlight.OutlineTransparency = 1
		NewHighlight.Parent = Target
		NewHighlight.Name = Target.Name.."Highlight"
		return NewHighlight
	end
end

--[[Removed]]
local function FadeInHighlight(Highlight, FadeIn)
	if Highlight == nil then return end
	local Goal = FadeIn and {OutlineTransparency = 0} or {OutlineTransparency = 1}
	local Tween = TweenService:Create(Highlight, TweenInfo.new(0.5), Goal)
	Tween:Play()
	warn("Applied Highlight")
end

--[[New]]
--[[local function FadeInHighlight(Highlight, FadeIn)
	repeat
		Highlight.OutlineTransparency = math.max(Highlight.OutlineTransparency - (task.wait() / FadeIn), 0)
	until Highlight.OutlineTransparency == 0
end]]

local function FadeOutAndDestroy(Highlight)
	if Highlight and Highlight.Parent then
		Highlight:Destroy()
		warn("Deleted Highlight")
	end
end

local function CheckClothes(PlayerName)
	local Shirt = game.Workspace[PlayerName]:FindFirstChild("Shirt")
	local Pants = game.Workspace[PlayerName]:FindFirstChild("Pants")
	if Shirt.ShirtTemplate == "http://www.roblox.com/asset/?id=1" or Shirt.ShirtTemplate == "http://www.roblox.com/asset/?id=1" or Shirt.ShirtTemplate == "http://www.roblox.com/asset/?id=1" or Shirt.ShirtTemplate == "http://www.roblox.com/asset/?id=1" and Pants.PantsTemplate == "http://www.roblox.com/asset/?id=1" or Pants.PantsTemplate == "http://www.roblox.com/asset/?id=1" or Pants.PantsTemplate == "http://www.roblox.com/asset/?id=1" or Pants.PantsTemplate == "http://www.roblox.com/asset/?id=1" then
		return true
	else
		return false
	end
end

--[[New]]
local function SetRaycastParams(Character)
	local RaycastParams = RaycastParams.new()
	RaycastParams.FilterDescendantsInstances = {Character}
	RaycastParams.FilterType = Enum.RaycastFilterType.Exclude
	RaycastParameters = RaycastParams
end

--[[New]]
SetRaycastParams(LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait())
LocalPlayer.CharacterAdded:Connect(SetRaycastParams)

local function UpdateTooltip()
	--[[New]] local Player, Character, MouseLocation = GetMouseData(RaycastParameters)
	local Target = Mouse.Target
	UpdateTooltipPosition()
	local IsWithinCameraMagnitude = (Head.CFrame.Position - Camera.CFrame.Position).Magnitude < CameraMagnitude
	
	if Target and Target.Parent then
		local IsHighlightedItem = false
		for _, Tags in pairs(HighlightItemsModule) do
			for _, TaggedItem in pairs(CollectionService:GetTagged(Tags)) do
				if TaggedItem == Target.Parent then
					IsHighlightedItem = true
					break
				end
			end
		end
		
		if IsHighlightedItem or Target.Parent:IsA("Model") and Target.Parent.Parent == game.Workspace or Target.Parent.Parent:IsA("Model") and Target.Parent.Parent.Parent == game.Workspace then
			local KitchenTrashcanAttribute = Target.Parent:GetAttribute("KitchenTrashcan")
			local PremiumTrashcanAttribute = Target.Parent:GetAttribute("PremiumTrashcan")
			local IsTrashcan = string.sub(Target.Parent.Name, 1, #"Trashcan") == "Trashcan"
			local HasUniform = CheckClothes(LocalPlayer.Name)
			local IsWithinItemMagnitude = nil
			if IsHighlightedItem and Target.Parent.Hitbox then
				IsWithinItemMagnitude = (Head.Position - Target.Parent.Hitbox.Position).Magnitude < ItemMagnitude
			end
			
			if IsTrashcan and not KitchenTrashcanAttribute and not PremiumTrashcanAttribute and IsWithinItemMagnitude and IsWithinCameraMagnitude then
				ItemTooltip.Text = Target.Parent:GetAttribute("ItemName") or ""
				if not Target.Parent:FindFirstChild(Target.Parent.Name.."Highlight") then
					local NewHighlight = CreateHighlight(Target.Parent)
					FadeInHighlight(NewHighlight, 0.5)
				end
			elseif Employee and IsWithinItemMagnitude and IsWithinCameraMagnitude and (Target.Parent.Parent.Parent.Name == "Kitchen" or Target.Parent.Parent.Parent.Parent.Name == "Kitchen") and HasUniform then
				ItemTooltip.Text = Target.Parent:GetAttribute("ItemName") or ""
				if not Target.Parent:FindFirstChild(Target.Parent.Name.."Highlight") then
					local NewHighlight = CreateHighlight(Target.Parent)
					FadeInHighlight(NewHighlight, 0.5)
				end
			elseif Employee and IsWithinItemMagnitude and IsWithinCameraMagnitude and (Target.Parent.Parent.Parent.Name == "BaristaLounge" or Target.Parent.Parent.Parent.Parent.Name == "BaristaLounge") then
				ItemTooltip.Text = Target.Parent:GetAttribute("ItemName") or ""
				if not Target.Parent:FindFirstChild(Target.Parent.Name.."Highlight") then
					local NewHighlight = CreateHighlight(Target.Parent)
					FadeInHighlight(NewHighlight, 0.5)
				end
			elseif HasPremium and Target.Parent.Name == "Trashcan7" and IsWithinItemMagnitude and IsWithinCameraMagnitude then
				ItemTooltip.Text = Target.Parent:GetAttribute("ItemName") or ""
				if not Target.Parent:FindFirstChild(Target.Parent.Name.."Highlight") then
					local NewHighlight = CreateHighlight(Target.Parent)
					FadeInHighlight(NewHighlight, 0.5)
				end
			end
		end
		
		--[[Old]]
		--[[if IsWithinCameraMagnitude and PlayerIsInGroup and not DestroyScript and ((Target.Parent:IsA("Model") and Target.Parent.Parent == game.Workspace) or (Target.Parent.Parent:IsA("Model") and Target.Parent.Parent.Parent == game.Workspace)) and not (Target.Parent:FindFirstChildWhichIsA("Highlight") or Target.Parent.Parent:FindFirstChildWhichIsA("Highlight")) then
			print("Check - A")
			DetectedNamesUserID = GetUserIDFromName(Target.Parent.Name)
			if DetectedNamesUserID then
				RealPlayersName = Players:GetNameFromUserIdAsync(DetectedNamesUserID)
				local NewHighlight = CreateHighlight(Target.Parent)
				PlayerInformation.Text = "@"..RealPlayersName.." ("..DetectedNamesUserID..")"
				.Text = "Cmd/Ctrl + Right Click to Select"
				FadeInHighlight(NewHighlight, 0.5)
				print("Player")
			end
		end
		
		for _, Model in pairs(game.Workspace:GetDescendants()) do
			if Model:IsA("Model") and Model.Name ~= Target.Parent.Name or (Head.CFrame.Position - Camera.CFrame.Position).Magnitude > CameraMagnitude then
				for _, ModelHighlight in pairs(Model:GetChildren()) do
					if ModelHighlight:IsA("Highlight") then
						print("Check - B [Deleted]")
						ItemTooltip.Text = ""
						PlayerInformation.Text = ""
						PlayerInformationSelectText.Text = ""
						RealPlayersName = ""
						UserIDBox.Text = ""
						UserIDBoxSelectText.Text = ""
						DetectedNamesUserID = 0
						FadeOutAndDestroy(ModelHighlight)
					end
				end
			end
		end]]
		
		--[[New]]
		if Player and Character ~= nil then
			local NewHighlight = CreateHighlight(Character)
			FadeInHighlight(NewHighlight, 0.5)
			local NewHighlight = Character:FindFirstChildOfClass("Highlight")
			PlayerInformationSelectText.Visible = true
			NewHighlight.Adornee = Character
			PlayerInformationSelectText.Position = UDim2.fromOffset(MouseLocation.X, MouseLocation.Y)
			PlayerInformationSelectText.Text = string.format(FormatText, Player.DisplayName, Player.UserId)
			if Thread == nil then
				Thread = task.spawn(FadeInHighlight)
			end
		--[[elseif Character ~= nil then
			for _, ModelHighlight in pairs(Character:GetChildren()) do
				if ModelHighlight:IsA("Highlight") then
					PlayerInformationSelectText.Visible = false
					ModelHighlight.Adornee = nil
					if Thread then
						task.cancel(Thread)
						Thread = nil
						ModelHighlight.OutlineTransparency = 1
					end
				end
			end]]
		end
		for _, Model in pairs(game.Workspace:GetDescendants()) do
			if Model:IsA("Model") and Model.Name ~= Target.Parent.Name or (Head.CFrame.Position - Camera.CFrame.Position).Magnitude > CameraMagnitude then
				for _, ModelHighlight in pairs(Model:GetChildren()) do
					if ModelHighlight:IsA("Highlight") then
						print("Check - B [Deleted]")
						ItemTooltip.Text = ""
						PlayerInformation.Text = ""
						PlayerInformationSelectText.Text = ""
						RealPlayersName = ""
						UserIDBox.Text = ""
						UserIDBoxSelectText.Text = ""
						DetectedNamesUserID = 0
						FadeOutAndDestroy(ModelHighlight)
					end
				end
			end
		end
	end
end

UserInputService.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.LeftControl then
		UserInputService.InputBegan:Connect(function(InputedObject)
			if InputedObject.UserInputType == Enum.UserInputType.MouseButton2 then
				if Mouse.Target and Mouse.Target.Parent:IsA("Model") and Mouse.Target.Parent.Parent == game.Workspace then
					PlayerInformation.Text = ""
					PlayerInformationSelectText.Text = ""
					UserIDBox.Text = "@"..RealPlayersName.." ("..DetectedNamesUserID..")"
					UserIDBoxSelectText.Text = "Cmd/Ctrl + C to Copy User ID"
					UserIDBox:CaptureFocus()
					UserIDBox.SelectionStart = 0
					UserIDBox.CursorPosition = #UserIDBox.Text + 1
					UserIDBox.Visible = true
				end
			end
		end)
	end
end)

UserInputService.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.LeftControl then
		UserInputService.InputBegan:Connect(function(InputedObject)
			if InputedObject.KeyCode == Enum.KeyCode.C and UserIDBoxSelectText.Text == "Cmd/Ctrl + C to Copy User ID" then
				UserIDBoxSelectText.Text = "Copied player information"
				wait(2)
				if UserIDBoxSelectText.Text ~= "Cmd/Ctrl + C to Copy User ID" then
					UserIDBox.Visible = false
					UserIDBox.Text = ""
					UserIDBoxSelectText.Text = ""
					PlayerInformation.Text = "@"..RealPlayersName.." ("..DetectedNamesUserID..")"
					PlayerInformationSelectText.Text = "Cmd/Ctrl + Right Click to Select"
				end
			end
		end)
	end
end)

RunService.RenderStepped:Connect(UpdateTooltip)

So I ended up just using my old FadeInHighlight function because I would run into issues using yours and so I just changed it back.

Then added the SetRaycastParams function and etc.

Added 1 new line in the UpdateTooltip function and the reset is at the bottom.

I found out that when I brought back my old code for the unhovering part and removing the highlight/text stuff, that when I move to the Characters Hair, it just thinks I’m not on the character anymore and unselects it. Here’s a gif of what I mean.
07aaad6325a5f1c6977fa3b3627aa1d8

If anyone has any ideas on how to help that would be greatly appreciated, and thank you so much JohhnyLegoKing and others for all you’ve done on this thread.

1 Like

After some thinking, I think I understand the problem a bit better now: It’s not that you don’t want hair to be detected at all, what you don’t want is hair to be detected as another player

Deleting these lines from the MouseData module should fix the issue (So long as you make sure that you use the Player returned by the GetMouseData function):

local accessory = raycastResult.Instance:FindFirstAncestorOfClass("Accessory")
if accessory and accessory.AccessoryType == Enum.AccessoryType.Hair then return end

On another note, I don’t know why you’re using the legacy mouse again, since the MouseData module should be able to do the same job but in a more customizable way

1 Like

I just want to let you know that I do see this! I will try to get back to this on Thursday as I am super busy tomorrow. Thanks for much for the help!!!

1 Like

I was about to go to bed and then thought I would try it because I felt bad lol… But commenting those 2 lines out didn’t change anything! (I’ve been joining the game on my Computer and on a different account on my phone to test this stuff btw.)

Is there anything I can do to better help you out? I have been trying to work on this for months and I just decided to make a dev form post about it, you’ve been a life savor! It’s 12:30AM as I’m writing this so hopefully I can get back to you soon. If not, ttyl.

Why not make it so that when Highlight is turned on, the player’s name is also displayed. In other words, make them work at and cleaned up the same time.

Or make a RenderSteeped function that makes sure that when a character is not highlighted, the player’s text information is deleted?

Edit:: Also I suggest using Tags so that this script doesn’t work on other Highlights, and in the script I wrote do a Highlight check with Highlight:HasTag()

Example:

local RS = game:GetService("RunService")

-- // Detecting player highlight //
local detecting
detecting = RS.RenderStepped:Connect(function()
	if not Target:FindFirstChildWhichIsA("Highlight") or not Character.Parent or Humanoid.Health <= 0 then
		-- // Make here player info delete func //
		detecting:Disconnect()
	end
end)

Thanks for the reply, but sadly this would not change anything, and I just tested it out as well!