How do I make it not detect players through walls???
local uis = game:GetService("UserInputService")
local localplayer = game.Players.LocalPlayer
local char = localplayer.Character or localplayer.CharacterAdded:Wait()
local enabler = script.Parent
local enabled = false
local camera = workspace.CurrentCamera
local mouse = localplayer:GetMouse()
function enabledisable()
if enabled == false then
enabled = true
enabler.TextColor3 = Color3.new(0, 255, 0)
else
enabled = false
enabler.TextColor3 = Color3.new(255, 0, 0)
end
end
uis.InputBegan:Connect(function(input, processed)
if not processed then
if input.KeyCode == Enum.KeyCode.E then
enabledisable()
end
end
end)
enabler.Activated:Connect(function()
enabledisable()
end)
game["Run Service"].Stepped:Connect(function()
if enabled == true then
for _, player in pairs(game.Players:GetPlayers()) do
if player ~= localplayer and player.Character and player.Character:FindFirstChild("Humanoid") and player.Character.Humanoid.Health > 0 then
local screenPos, onScreen = camera:WorldToScreenPoint(player.Character.HumanoidRootPart.Position)
if onScreen then
local mousepos = uis:GetMouseLocation()
local screenPosVector = Vector2.new(screenPos.X, screenPos.Y)
local distance = (screenPosVector - mousepos).Magnitude
if distance < 125 then
local direction = (player.Character.HumanoidRootPart.Position - char.HumanoidRootPart.Position).Unit * 1000
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {char}
local result = workspace:Raycast(char.HumanoidRootPart.Position,direction, raycastParams)
if result then
print("near")
camera.CFrame = CFrame.new(camera.CFrame.Position, player.Character.Head.Position)
end
else
print("far")
end
end
end
end
end
end)