Delete the Mouse.Target

Hello,
In my game we have the possibility to push another player by pressing “E”, but we have to put the mouse cursor on the player to be able to trigger “E”.
I’d like to remove the “Mouse.target” so that we can just push the player by being next to it without necessarily pointing it with the mouse cursor. it’s possible ?

Here is the Local Script in StarterCharacterScript:

local Players = game:GetService('Players')
local Player = Players.LocalPlayer  
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

local Rep = game:WaitForChild("ReplicatedStorage")
local SoundPlay = Rep:WaitForChild("PlaySoundH")




local Mouse = Player:GetMouse()
local Limit = 5
local UIS = game:GetService('UserInputService')

local Events = game:GetService('ReplicatedStorage'):WaitForChild('Events')


function GetPlayer(Part) 
	if Part:FindFirstChild("Humanoid") then 
		return Part, true
	end

	if Part:IsA("Accessory") then 
		if Part.Parent:FindFirstChild("Humanoid") then 
			return Part.Parent, true
		end
	end
end





UIS.InputBegan:Connect(function(Key)
	local distance = (Mouse.Hit.p - Player.Character.HumanoidRootPart.Position).Magnitude
	if distance < Limit then
		if Key.KeyCode == Enum.KeyCode.E then
		if Mouse.Target then 
				local PossibleTarget, Has = GetPlayer(Mouse.Target.Parent)

			
			
			if Has then 
					Events.Spells:FireServer(PossibleTarget,'TkPush',Camera.CFrame.LookVector)
					SoundPlay:FireServer("rbxassetid://9117969717", 100, 0.5)
					
					local Animation = Instance.new('Animation')
					Animation.AnimationId = 'rbxassetid://10793040097'
					local Track = Character.Humanoid.Animator:LoadAnimation(Animation)
					Track:Play()
			end
		  end
	   end
	end
end)

and this one (I don’t know if it’s necessary for you to see it) It’s a moduleScript in ServerScriptService.

local module = {}

local DebriService = game:GetService('Debris')

local Rep = game:GetService("ReplicatedStorage")
local SoundReact = Rep:WaitForChild("PlaySoundH")


local TKPushData = {
	DebounceTime = 3,
	Debounce = {},
	Victims = {},
}


function CheckDebounce(Character,Target)
	local CanAttackVictim = true 
	local CanAttack = false 
	
	if not TKPushData['Debounce'][Character] then 
		TKPushData['Debounce'][Character] = {
			Last = tick()+TKPushData['DebounceTime']
		}
		CanAttack = true 
	end
	
	if TKPushData['Debounce'][Character] then 
		if tick() - TKPushData['Debounce'][Character]['Last'] >= TKPushData['DebounceTime'] then 
			CanAttack = true 
		end
	end
	
	if  TKPushData[table.find(TKPushData['Victims'],Target)] then
		CanAttackVictim = false
	end
	
	if CanAttack==true and CanAttackVictim==true then 
		return true 
	end
		
		--Targets[table.find(Targets, Target)]

end

module.TelekineticPush = function(Character,Target,CameraVector)
	local HRP = Character.HumanoidRootPart 
	
	local THRP = Target.HumanoidRootPart 
	local TRagdoll = Target.Ragdoll
	
	if CheckDebounce(Character,Target) == true then 
		TKPushData['Debounce'][Character] = {Last = tick()}
		local Force = Instance.new('LinearVelocity')
		TRagdoll.Value += 2
		local Force = Instance.new("BodyVelocity")
		Force.MaxForce = Vector3.new(30000,math.huge,30000)
		Force.P = math.huge
		Force.Velocity = Vector3.new(45,0,45) *CameraVector
		Force.Velocity += Vector3.new(0,5,0)
		Force.Parent = THRP 
		DebriService:AddItem(Force,.3)
		
		

		SoundReact.OnServerEvent:Connect(function(plr, SoundId, Range, Volume)
			local Character = plr.Character
			if Character then
				local HeadInstance = Character:FindFirstChild("Head")
				if HeadInstance then
					local NewSound = Instance.new("Sound",HeadInstance)
					NewSound.SoundId = SoundId
					NewSound.RollOffMaxDistance = Range
					NewSound.Volume = Volume
					NewSound:Play()
					NewSound.Ended:Connect(function()
						NewSound:Destroy()
					end)
				end
			end
		end)

		
		
		
		wait(TKPushData['DebounceTime'])
		for _, v in pairs(TKPushData['Victims']) do 
			if v == Target then 
				table.remove(TKPushData['Victims'],v)
			end
		end
	end
	
	
	
end







return module

You can use magnitude to find the distance between two points (Vector3 - Vector3).Magnitude is the distance between them.

and how can i change this in my scripts? I am an amateur :roll_eyes:

This topic could help you.
Also I recommend to put :LoadAnimation outside of the function, because it will load a new animation each time that function triggers

I would recommend creating proximity prompts for the players (could be on localScript or server script depending on how the game works) and then connecting the function to that.

I want to keep my system, all I want is not to need the mouse cursor to Press E ,if anyone can show me how to modify the script for this?