Using MouseHoverEnter and Leave to make a Character avatar go transparent

What I am trying to create is a mechanic where if the current player hovers over another player’s torso or head their whole body goes transparent to an extent.

I am on track of sort of figuring out the code for this but I have an issue where when I hover over the head of another player it doesn’t work at all and when I hover over the torso of another player it only works when I hover in the gaps between the arm and torso.

This video shows the problem (Excuse the long loading I am on HP laptop…) and what I am trying to achieve.

At first, I thought it was the clothes but I removed the clothes and the problem still continued. I also tried checking if something was in front of the torso by looking through rigs and there isn’t anything.

I have a more complex script to achieve what I am trying to do but for simplicity purposes when showing you guys the problem, I made a simple code that gets across the idea of what I am trying to do and what I have been doing in my other scripts.

Example of Code:

local avatar = workspace.myavatar
local clickdetect = script.Parent
local body = {
	avatar.Head,
	avatar.LeftFoot,
	avatar.LeftHand,
	avatar.LeftLowerArm,
	avatar.LeftLowerLeg,
	avatar.LeftUpperArm,
	avatar.LeftUpperLeg,
	avatar.LowerTorso,
	avatar.RightFoot,
	avatar.RightHand,
	avatar.RightLowerArm,
	avatar.RightLowerLeg,
	avatar.RightUpperArm,
	avatar.RightUpperLeg,
	avatar.UpperTorso,
}

clickdetect.MouseHoverEnter:Connect(function()
	for _, v in body do
		v.Transparency = 0.6
	end
end)

clickdetect.MouseHoverLeave:Connect(function()
	for _, v in body do
		v.Transparency = 0
	end
end)

NOTE: I put the click detector in the UpperTorso before I tested so I didn’t need to do the coding for that.

Honestly baffled as to why it isn’t working; I’m kinda afraid that this isn’t possible on Roblox at all because if it isn’t, my whole mechanic is out the window along with my days of scripting…

Thank you for your help!

1 Like

ClickDetectors will work if parented to a model. Try parenting directly to the Character.

The reason that it currently only works between the torso and arm is because the HumanoidRootPart is actually an invisible part that does not animate with the rest of the character rig, so the UpperTorso would be obscuring it.

4 Likes

I specifically wanted it to be if the torso or head were hovered over but if that’s not possible this works great. Now that I am thinking about it, making it so that only if the head or torso were hovered over the avatar would go transparent is kind of inefficient and dumb in terms of what I am using it for so this works perfectly actually.
Thank you so much, this worked perfectly and helped lots!

2 Likes

I think I know the fix for this. In the example you showed, your hair accessory is actually blocking the ClickDetector. That’s why you can only click on the “gaps” near the shoulders.

To fix this, you’ll need to set every accessory’s CanCollide and CanQuery property to false. In a script, all you need to do is make sure that whenever a character spawns and all accessories are loaded, just loop through all the parts in all accessories in a character and turn those off.

You’ll need to run it every time a character spawns and all the accessories are loaded.

EDIT: Didn’t notice it was already solved, I wrote this an hour ago and only got a chance to send it now😅 If you’re still going for torso/head only you can use what I wrote here.

2 Likes

Hey, it’s quite late where I live currently so I will try what you suggested in the morning.

Thanks for the help though!

1 Like

Thank you so much it worked perfectly! I selected yours as the solution because it is what I originally wanted and I am still questioning whether I should have the body go transparent when hovered over the character model or when hovered over the torso and head. However, I will probably reach that conclusion later on when everything is sorted.
Thanks again!

1 Like

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