Sorry, Im really new at scripting it's giving me an error over hunting. I have looked for a while and I'm not sure what's wrong with it. any help would be awesome. Thanks!

local mypart = Instance.new("Part",workspace)
local myPos = Vector3.new(0,10,0)
local myLook = Vector3.new(0,1,0)
local myCFrame = CFrame.new(myPos,myLook)
mypart.Anchored = true

while (1) do
	mypart.CFrame = myCFrame
	Pigred72 = workspace:WaitForChild("Pigred72")
	myLook = Pigred72.HumanoidRootPart.Position
	myCFrame = CFrame.new(myPos,myLook)
	wait ()
end

local function getClosestAvatarPostion(part)
	local Players = game.Players:GetChildren()
	local PlayerPostion = {}
	if #PlayerPostion then
		
		for key, Player in pairs(Players) do
			local plName = Player.Name
			local plPos = game.Workspace:WaitForChild(Player.Name).HumanoidRootPart.Positon
			local plDis = (part.Position - plPos).magnitude
			table.insert(PlayerPostion,key{plName,plPos,plDis})
		end
		
		Hunting = PlayerPostion[1]
		
		for x = 1,#PlayerPostion,1 do
			if PlayerPostion[x][3] < Hunting[3]then
				Hunting = PlayerPostion[x]
			end
		end
		if Hunting then
			return Hunting[2]
			else
		   return part.Postion	
		end
		 
	 else
		return part.Postion 	
	end
end

4 comments

0

What is the error and which line?

0

Line 27 Hunting

0

it has a Error over The Hunting on Line 27 and I have no idea why

0

Change Hunting = PlayerPostion[1] on line 27 to local Hunting = PlayerPostion[1]