-
What do you want to achieve? I want to allow the character of the Local Player to be found using Mouse.Target
-
What is the issue? The character of the Local Player is ignored by the mouse/ is already on the Mouse.TargetFilter list by default, is there any way to change this?
-
What solutions have you tried so far? I already tried looking for ways to do what I want but I found nothing that helps me. So I came on here and posted this topic hoping someone can help me.
yes, but you have to remake the Mouse.Hit property using a ray. Like this:
local plr = game:GetService("Players").LocalPlayer
local camera = workspace.CurrentCamera
local mouse = plr:GetMouse()
function getMouseHitIncludingChar()
local vector = mouse.Hit.p - camera.CFrame.p
local ray = workspace:Raycast(camera.CFrame.p, vector.Unit * (vector.Magnitude + 5), RaycastParams.new())
return ray and CFrame.lookAt(ray.Position, ray.Position + ray.Normal) or nil
end
local mouseHit = getMouseHitIncludingChar()
This solves one problem (Mouse can now touch player), but it cannot tell me what exactly the mouse is touching, which doesn’t really solve the original problem I wanted help with.
How so? You can get anything you need to with a ray.
All I’m getting with this ray is just a CFrame (in print() and I can’t get anything else out of it), sorry if I seem a little dumb lol, I have never used RayCasting until now. Here are the parts of the script you need to see (not complete script), please tell me if I’m doing something wrong.
-- RayCastParams
local RayCastParamThing = RaycastParams.new()
RayCastParamThing.FilterType = Enum.RaycastFilterType.Blacklist
RayCastParamThing.FilterDescendantsInstances = {script.Parent}
RayCastParamThing.IgnoreWater = true
-- function
function getMouseHitIncludingChar()
local vector = Mouse.Hit.p - game.workspace.CurrentCamera.CFrame.p
local ray = workspace:Raycast(game.workspace.CurrentCamera.CFrame.p, vector.Unit * (vector.Magnitude + 5), RayCastParamThing)
return ray and CFrame.lookAt(ray.Position, ray.Position + ray.Normal) or nil
end
-- constant updater of the Green Circle's Position.
repeat
local mouseHit = getMouseHitIncludingChar()
print(mouseHit) -- This just gives a CFrame
Mouse.Button1Down:Connect(function()
if HoldingDebounce == true then
ClickDebounce = true
end
end)
-- GreenCircle.Position = Mouse.Hit.Position
GreenCircle.CFrame = mouseHit
GreenCircle.Orientation = Vector3.new(0,0,90)
wait(.001)
until ClickDebounce == true
I found a solution, by changing one of the lines
I replaced the original return section with return ray, and added (:Instance:GetFullName()) to the end of mouseHit which gave me what I was looking for!
-- function
function getMouseHitIncludingChar()
local vector = Mouse.Hit.p - game.workspace.CurrentCamera.CFrame.p
local ray = workspace:Raycast(game.workspace.CurrentCamera.CFrame.p, vector.Unit * (vector.Magnitude + 5), RayCastParamThing)
--return ray and CFrame.lookAt(ray.Position, ray.Position + ray.Normal) or nil
return ray
end
local mouseHit = getMouseHitIncludingChar()
print(mouseHit.Instance:GetFullName())
-- workspace.ilovegohan.HumanoidRootPart