How to Make the Mouse.Target.Position, more bigger [Sulutionated]

hi im making a game that is inspired highly to some tsb games and jjs, im been making a gojo character, and i wanted to make his Ability “Blue” similar how jjs made it, but i notice that apart from my game, jjs when you aim your mouse, THE MOUSE has a range, but in my game the range the MOUSE is just like a point, see the footage to understand

i dont want to copy, i just want to replicate the mechanic

Forgort to mention the script i made for it:

			["blue"] = function(argu)
				if chr:GetAttribute("activu") == true then
					return 
				end
				if argu then
					local horp = argu.Parent:FindFirstChild("HumanoidRootPart")
					if not argu.Parent:FindFirstChild("HumanoidRootPart") then
						return
					end
					local magnitude = (horp.Position - rot.Position).magnitude
					if 20 > magnitude then
						if argu and argu.Parent:FindFirstChild("Humanoid") then
							local anim: Animation = human:LoadAnimation(Ability_Char_Stuff.Animations.Blue)				
							anim:Play()
							if argu then
								print("hi")
							end
							anim:GetMarkerReachedSignal("Use"):Connect(function()
								visualizerremote:FireAllClients(player, "blue_gojo", rot.CFrame * CFrame.new(0,1,-5))
								Main_Basics.CreateCD(player.Character, "R", 5, nil, nil, true)
							end)
						end
					end
				end
			end;

this is from server so, “argu” stands for “Mouse.Target.Postion”

2 Likes

i downscale the video btw, so yall dont need to download the video

1 Like

Hey, amarodjdja!

You need to use workspace:GetPartBoundsInRadius() in order to get all parts in a radius around the mouse’s hit position.

Example:

local Script,Game,Workspace = script,game,workspace
local Players = Game:GetService("Players")
local UserInputService = Game:GetService("UserInputService")

local Player = Players.LocalPlayer
local Camera = Workspace.CurrentCamera

local radius = 10

local function Get_Mouse_Position_In_3D_Space()
	local mousePosition = UserInputService:GetMouseLocation()
	local rayData = Camera:ScreenPointToRay(mousePosition.X,mousePosition.Y)
	local ray = Workspace:RayCast(rayData.Origin,rayData.Direction*1024)
	return ray
end

local function Get_Parts_Near_Mouse_Position()
	local position = Get_Mouse_Position_In_3D_Space()
	if not position then return {} end
	local parts = Workspace:GetPartBoundsInRadius(position,radius)
	return parts
end

Get_Parts_Near_Mouse_Position() -- Calling this would return parts in a 10 stud radius.

I used Camera and UserInputService as it’s more of a modern approach on getting the mouse’s target.

is yelling me an error in the second function, im using server, now argu is this:

			local mouseposition = UIS:GetMouseLocation()
			local mon = game.Workspace.CurrentCamera:ScreenPointToRay(mouseposition.X, mouseposition.Y)

this is server:

			["blue"] = function(argu)
				if chr:GetAttribute("activu") == true then
					return 
				end
				local radius = 20

				local function Get_Mouse_Position_In_3D_Space()
					local rayData = argu
					local ray = game.Workspace:Raycast(rayData.Origin,rayData.Direction * 1024)
					print(ray)
					return ray
				end

				local function Get_Parts_Near_Mouse_Position()
					local position = Get_Mouse_Position_In_3D_Space()
					if not position then 
						return {}
					end
					local over = OverlapParams.new()
					over.FilterType = Enum.RaycastFilterType.Exclude
					over.FilterDescendantsInstances = {chr}

					local raycastResult = workspace:GetPartBoundsInRadius(position, radius, over)
					if raycastResult then
						return raycastResult.Position
					else
						return nil
					end
				end
				local p = Get_Parts_Near_Mouse_Position()
				if p then
					for i, v in pairs(p) do
						local ehum = v.Parent:FindFirstChild("Humanoid") or v.Parent.Parent:FindFirstChild("Humanoid")
						if ehum and ehum.Parent ~= chr then
							print(chr)
						end
						break
					end
				end

			end;

im kinda lost, i dont know about mouse stuff and camera with it

i try all in client and send the “Get_Parts_Near_Mouse_Position” to the server, but still gave me errors

Can you please show me the error?

sorry i went to sleep, here

i dont know what to do there
honestly

raycastResult is a object not a vector3, what happens on line 130? you probs have written something like thing.Position = raycastResult. when you want to do thing.Position = raycastResult.Position.

Here you can see the values contained within the raycastResultobject and their indexes…

yeah im kinda dumb here, i forgot to idk, do some stuff that you were saying about the index and .Position:

				local radius = 20

				local function Get_Mouse_Position_In_3D_Space()
					local rayData = argu
					local ray = game.Workspace:Raycast(rayData.Origin,rayData.Direction * 1024)
					print(ray)
					return ray.Instance
				end

				local function Get_Parts_Near_Mouse_Position()
					local position = Get_Mouse_Position_In_3D_Space()
					if not position then 
						return {}
					end
					local over = OverlapParams.new()
					over.FilterType = Enum.RaycastFilterType.Exclude
					over.FilterDescendantsInstances = {chr}

					local raycastResult = workspace:GetPartBoundsInRadius(position.Position, radius, over)
					
					return raycastResult
				end
				local p = Get_Parts_Near_Mouse_Position()
				if p then
					for i, v in pairs(p) do
						local ehum = v.Parent:FindFirstChild("Humanoid") or v.Parent.Parent:FindFirstChild("Humanoid")
						if ehum and ehum.Parent ~= chr then
							print(ehum, v.Parent)
						end
						break
					end
				end

though idk what im doing wrong a bit, cuz is only getting a character, maybe i should change this:

				local p = Get_Parts_Near_Mouse_Position()
				if p then
					for i, v in pairs(p) do
						local ehum = v.Parent:FindFirstChild("Humanoid") or v.Parent.Parent:FindFirstChild("Humanoid")
						if ehum and ehum.Parent ~= chr then
							print(ehum, ehum.Parent)
						end
						break
					end
				end

cuz im using break probably

change ray.Instance to ray.Position in Get_Mouse_Position_In_3D_Space()
cos ray.Instance is the position of the object the ray hit, and i think you want ray.Position cos that is the position at which the ray hit

1 Like

i did, did good change, but i still have issues for finding like the humanoid on the character, it just get parts, and if i try to find the Humanoid, or check if is a model, this show on the output:

				local p = Get_Parts_Near_Mouse_Position()
				if p then
					if p.Parent:IsA("Model") then
						print(p.Parent:IsA("Model"))
					else
						return
					end
				end

(btw if you just put “print(p)” prints out the objects that youre pointing at, or close by it)

you could do

if part.Parent then
     if part.Parent:FindFirstChild("Humanoid") then
     -- part is part of a character so 
     return part.Parent
     end
end

You are getting that error because the part you are examining is parented to the workspace and the workspace doesnt have the :IsA() function

			["blue"] = function(argu)
				if chr:GetAttribute("activu") == true then
					return 
				end
				local radius = 20

				local function Get_Mouse_Position_In_3D_Space()
					local rayData = argu
					local ray = game.Workspace:Raycast(rayData.Origin,rayData.Direction * 1024)
					return ray.Position
				end

				local function Get_Parts_Near_Mouse_Position()
					local position = Get_Mouse_Position_In_3D_Space()
					if not position then 
						return {}
					end
					local over = OverlapParams.new()
					over.FilterType = Enum.RaycastFilterType.Exclude
					over.FilterDescendantsInstances = {chr, workspace.Map, workspace.Effects}

					local raycastResult = workspace:GetPartBoundsInRadius(position, radius, over)
					
					-- Find the closest character (model with Humanoid)
					local closestCharacter = nil
					local closestDistance = math.huge

					for _, part in ipairs(raycastResult) do
						local model = part:FindFirstAncestorOfClass("Model")
						if model and model:FindFirstChildOfClass("Humanoid") then
							local distance = (model.PrimaryPart.Position - position).magnitude
							if distance < closestDistance then
								closestDistance = distance
								closestCharacter = model
							end
						end
					end

					-- Print the closest character's name (if found)
					if closestCharacter then
						print("Closest character:", closestCharacter.Name)
					else
						print("No character found near the mouse position")
					end

					return closestCharacter
				end

				-- Call the function to get nearby characters
				local closestCharacter = Get_Parts_Near_Mouse_Position()

			end;
1 Like

It seems like the issue was because I did not add a .Position after the position variable. Adding that will fix the issue.

I see that you have already found your solution, good job. I would argue that you mark my reply as the solution as I gave the general answer for how to get parts near the mouses position.