Script:
--//Parts to look at
local Scrap_Root = workspace.Enemies.Scrap
--//Services
local Player_Service = game:GetService("Players")
local Run_Service = game:GetService("RunService")
--//Values
local Max_Distance = 300
local Scrap_Detected = {}
local Player_Raycasts = {}
--//Tables
local Detector_Functions = {}
--//Main Script
function Detector_Functions.Camera_RayCast(player)
local Character = player.Character or player.CharacterAdded:Wait()
if Player_Raycasts[player] then
return
end
local Head = Character:WaitForChild("Head")
local Head_Position = Head.CFrame.Position
local Head_Direction = Head.CFrame.LookVector
local RayCast_Params = RaycastParams.new()
RayCast_Params.FilterDescendantsInstances = {Character, Scrap_Root.Torso}
local RayCast = workspace:Raycast(Head_Position, Head_Direction * Max_Distance, RayCast_Params)
print("RayCast Was Created For " .. player.Name)
Player_Raycasts[player] = true
Run_Service.Heartbeat:Connect(function()
if RayCast and RayCast.Instance then
print("Ray Hit " .. RayCast.Instance.Parent.Name)
Scrap_Detected[player] = true
else
print("Ray Hit Nothing")
Scrap_Detected[player] = false
end
end)
end
function Detector_Functions.Detector()
local Speed_Value = 16
for i, detected in pairs(Scrap_Detected) do
if detected then
Speed_Value = 0
break
elseif script.Parent.SeesTarget.Value == true then
Speed_Value = 70
end
end
script.Parent.Parent.Humanoid.WalkSpeed = Speed_Value
end
return Detector_Functions