Objective: Make a script that makes the npc's hitbox part visible when the player has the tool equipped and have their mouse on the hitbox.
Problem: The hitbox turns visible when hovered over but I don't know how to make the hitbox to go back to normal when the tool isn't equipped and when they aren't pointing at the hitbox.
In my game there is a folder in workspace named npcs and inside it are the npcs. Each npc has a part in them named hitbox which is what I'm trying to edit. This is a local script inside a tool's handle.
player = game.Players.LocalPlayer
handle = script.Parent
tool = script.Parent.Parent
tool.Equipped:connect(function(mouse)
while tool:IsDescendantOf(player.Character) do -- Loops while the tool is in the player's character (equipped)
wait(0.1)
ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - handle.CFrame.p).unit * 30)
-- Makes the rays
part = workspace:FindPartOnRay(ray, player.Character, false, true)
-- finds the part
if part then -- checks if it found a part.
if part.Name == "Hitbox" and part:IsDescendantOf(workspace.NPCs) then
-- checks if the part is a hitbox and it is a descendant of the NPC folder.
part.Transparency = 0 -- Changes part transparency
else
print("Part Not Hitbox") -- If the part isn't a npc's hitbox
end
else
print("Not part") -- If the ray didn't get a part.
end
end
end)

3 comments
Thanks
Is there a way to make it so it only works within a certain distance?
yes, add me on roblox and I make it for you