How do i make it so my npc won't stop when i look at him through the wall

npc stops when i look at him through the wall

i tried adding Raycast in Local script but it didn’t work and i have zero idea how do i add Raycast to server since i cant really use for i loop to find a player because remote events exhaust

client:

local Run_Service = game:GetService("RunService")
local Replicated_Storage = game:GetService("ReplicatedStorage")

local part = workspace.Scrap:WaitForChild("HumanoidRootPart")
local cam = workspace.CurrentCamera

local Looking_Remote = Replicated_Storage.Remotes.Looking_Remote
local Not_Looking_Remote = Replicated_Storage.Remotes.Not_Looking_Remote

local player = game.Players.LocalPlayer

		Run_Service.Heartbeat:Connect(function()
			local isOnScreen = select(2, cam:WorldToViewportPoint(part.Position))
			if isOnScreen then
				Looking_Remote:FireServer()
			else
				Not_Looking_Remote:FireServer()
			end
		end)

Server:

local value = 6

local connection1:RBXScriptConnection = nil
local connection2:RBXScriptConnection = nil

local Run_Service = game:GetService("RunService")

	Run_Service.Heartbeat:Connect(function()
	connection1 = game.ReplicatedStorage.Remotes.Looking_Remote.OnServerEvent:Connect(function()
		value = 0
		connection1:Disconnect()
	end)

	connection2 = game.ReplicatedStorage.Remotes.Not_Looking_Remote.OnServerEvent:Connect(function()
		value = 100
		connection2:Disconnect()
	end)

	script.Parent.Parent.Humanoid.WalkSpeed = value

	end)


4 Likes

and the game gets a bunch of lag

3 Likes