Untitled

 avatar
unknown
plain_text
2 years ago
1.5 kB
1
Indexable
local scriptt = script
scriptt.Name = "NpcsScript"

local npc = script.Parent

--[[ "Normal","Scared","More Scared","Very Scared"
local normalState = true
local scaredState = false
local morescaredState = false
local veryscaredState = false
--]]

local fearparts = workspace.FearParts

local maxDistance = 10

--[[local npchead = script.Parent:WaitForChild("Head")
--local ChatService = game:GetService("Chat")
ChatService:Chat(npchead, "I am an NPC! :)","Blue")
--]]

for i, fearpart in ipairs(fearparts:GetChildren()) do
	
    local findfearparts = fearparts:FindFirstChild("FearPart")

	if findfearparts then
		print("I found a part")
		-- check if npc is close to the part
    	local distance = (npc.HumanoidRootPart.Position - fearpart.Position).Magnitude

		if distance <= maxDistance then

			--if veryscaredstate == true then
			--veryscaredsstate(4th state)
			--[[
			local PathFidingService = game:GetService("PathfindingService")
			
			local npchumanoid = script.Parent:WaitForChild("Humanoid")
            local npcuppertorso = script.Parent:WaitForChild("UpperTorso")

			local path = PathFidingService:CreatePath()
			path:ComputeAsync(npcuppertorso.Position, workspace.Character.Position)

			local waypoints = path:GetWaypoints()

			for i, waypoint in ipairs(waypoints) do
			npchumanoid:MoveTo(waypoint.Position)
			npchumanoid:MoveToFinished()
			wait(2)
			end
			--]]
			--end
		end
	end
end
Editor is loading...