I want a highlight to be clickable like this in the video. The cursor is kinda glitchy because of recorder issues but don’t mind that hehe.
What do you mean? Highlights aren’t clickable but ClickDetectors are?
Highlights
are for detail Purposes, They are meant to Indicate a Object, Person, or an Objective, to make them way easier to see.
But as @bluebxrrybot said, you are able to use ClickDetectors
for this functionality, but the only issue preventing you from doing this is their range which can be easily fixed by changing the MaxActivationDistance
, The Default is 32
.
However, Clickdetectors cant be activated behind walls, and far away distances make it harder to click, but You can either:
-
Create a Hitbox to better in Clicking
This is so you have a Easier time clicking the Character as going further away will make it harder,. -
Ray Cast based on your Mouse Hit direction and Get the Character
This would require ignoring the workspace but the Characters contained in them, you should store the map, and make it so it ignores the descendants (all children) and get the Character who aren’t a Descendant of the map. -
Use a Character Itself
This would make it so the Character, depending on where theClickDetector
is can be Clicked.
If your mouse is suppossed to be hovering over the highlight, then you can use mouse properties and filtering to check if you’re hovering over a character. Or, you can use raycasts with filtering like @xGOA7x said.
You can loop the whole workspace to check what has the highlight.
Example:
for _, highlight in ipairs(game:GetService('Workspace'):GetDescendants()) do
if highlight:IsA('Highlight') and highlight.Parent:IsA('Model') and highlight.Parent:FindFirstChildWhichIsA('Humanoid') then
local ClickDetector = Instance.new('ClickDetector', highlight.Parent:WaitForChild('HumanoidRootPart'))
ClickDetector.Name = 'ClickDetector'
end
end
That isnt what they are asking:
They want the highlight to clickable.
This wouldnt work as you are basically loop to give a Highlight
a ClickDetector
, something that isnt clickable.
Plus, the Hightlight may not even the Parented to the Instance, it may be Adornned to it.
My bad, I’m trying to put the highlight into the hrp of the character
The issue is, the highlight can show through walls, but the click detector can’t detect clicks through walls.
Also why did you use game:GetService("Workspace")
. Please
idk, people:
-- PAIN O METER 9000!!
Game -- Deprecated (Idk why)
game -- DataModel
game.Workspace -- I guess this works...space
Game.Workspace -- Deprecated DataModel (Idk why)
workspace -- YESSSSS
Workspace -- Deprecated (Idk why)
game:GetService("Workspace") -- you are weird
game:FindService("Workspace") -- you are weirder
game:WaitForChild("Workspace") -- WHY IN THE-
game:FindFirstChild("Workspace") -- WHAT THE-
game:FindFirstChildOfClass("Workspace") -- AUUUUUUUUUAAAAAAAAAAAAAAAAAAH
game:FindFirstChildWhichIsA("Workspace") -- AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
I’m doing that to get the real workspace, in case their game have anti-cheat (Just my old habit with anti-cheats).
Well actually, you can’t use mouse properties for this, so forget about that. You would have to utilize raycasts when you click to see if you’re hovering over a player, even through walls.
Basically, I have done some research. So you can change any objects / instances in the player character from the client side, because when the player character objects / instances got changed from the client, It will also change on the server such as the humanoid health, speed, jump power, etc…
that’s interesting… uhhh i guess u could use a raycast that has a filter descendants list of the map but not the characters with the highlight, then see if the raycast hit one of the characters? all i can think of, this is super complex-looking lol
this is kinda pseudocode since i havent touched raycasts in a hot minute but i might aswell try to give you something to start off with, have your map in one folder in workspace and the NPCs/characters in another,
local Camera = workspace.CurrentCamera
local Mouse = game.Players.LocalPlayer:GetMouse()
----------------------------------
-- If Mouse.Hit is nil (eg. it's touching the skybox) then don't do anything
if not Mouse.Hit then return end
-- Make some raycast params, ignore the map and only focus on the NPCs
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {workspace.Map}
Params.FilterType = Enum.RaycastFilterType.Blacklist
-- Raycast from the camera to the mouse's 3D position
local Result = workspace:Raycast(Camera.CFrame.Position, Mouse.Hit.Position, Params)
-- Check if the result and its instance aren't nil, then go from there
if Result and Result.Instance then
local Ins = Result.Instance
if Ins:IsDescendantOf(workspace.NPCs) then
-- do ya magic!
end
end
roblox deprecated things they found to have inconsistent capitalization lol, i get your pain though
Hopefully this works, otherwise consider it a base or something:
local uis = game:GetService("UserInputService")
local raydist = 500
local function HitCharacter(char)
warn("Hit the player:", char)
end
uis.InputBegan:Connect(function(input, process)
if not process then return end
if input.UserInputType == Enum.UserInputType.Mouse or input.UserInputType == Enum.UserInputType.Touch then
local unitray = game.Players.LocalPlayer:GetMouse().UnitRay
local origin = unitray.Origin
local direction = unitray.Direction * raydist
local args = RaycastParams.new()
args.FilterType = Enum.FilterType.Whitelist
--\\ Raycasting
local chars = {}
for _, player in pairs(game.Players:GetPlayers()) do
if player.Character and game.Players.LocalPlayer ~= player then
if player.Character.Humanoid.Health > 0 and player.Character:FindFirstChild("Highlight") then
table.insert(chars, player.Character)
end
end
end
args.FilterDescendantsInstances = chars
local result = workspace:Raycast(origin, direction, args)
if result then
HitCharacter(result.Instance:FindFirstAncestorOfClass("Model"))
end
end
end)
You should Probably check if there is a model otherwise it might error.
There’s a 100% chance it will be a model, because I’m only putting characters in the filter.
wouldn’t that make it ignore them?