local z=waitForChild(sp,"\084\111\114\115\111")local p=waitForChild(sp,"\072\101\097\100")local K=waitForChild(z,"\082\105\103\104\116 \083\104\111\117\108\100\101\114")local M=waitForChild(z,"\076\101\102\116 \083\104\111\117\108\100\101\114")local b=waitForChild(z,"\082\105\103\104\116 \072\105\112")local h=waitForChild(z,"\076\101\102\116 \072\105\112")local N=waitForChild(z,"\078\101\099\107")local y=waitForChild(sp,"\072\117\109\097\110\111\105\100")local q="\083\116\097\110\100\105\110\103"local P=waitForChild(z,"\072\105\116\083\111\117\110\100")local o={waitForChild(z,"\071\104\111\115\116\049\083\111\117\110\100"),waitForChild(z,"\071\104\111\115\116\050\083\111\117\110\100")}if healthregen then local z=waitForChild(sp,"\072\101\097\108\116\104\082\101\103\101\110\101\114\097\116\105\111\110\083\099\114\105\112\116")z.Disabled=false end y.WalkSpeed=wonderspeed local x="\078\111\110\101"local D=0 function onRunning(z)if z>0 then q="\082\117\110\110\105\110\103"else q="\083\116\097\110\100\105\110\103"end end function onDied()q="\068\101\097\100"end function onJumping()q="\074\117\109\112\105\110\103"end function onClimbing()q="\067\108\105\109\098\105\110\103"end function onGettingUp()q="\071\101\116\116\105\110\103\085\112"end function onFreeFall()q="\070\114\101\101\070\097\108\108"end function onFallingDown()q="\070\097\108\108\105\110\103\068\111\119\110"end function onSeated()q="\083\101\097\116\101\100"end function onPlatformStanding()q="\080\108\097\116\102\111\114\109\083\116\097\110\100\105\110\103"end function moveJump()K.MaxVelocity=.5 M.MaxVelocity=.5 K.DesiredAngle=3.14 M.DesiredAngle=-3.14 b.DesiredAngle=0 h.DesiredAngle=0 end function moveFreeFall()K.MaxVelocity=.5 M.MaxVelocity=.5 K.DesiredAngle=3.14 M.DesiredAngle=-3.14 b.DesiredAngle=0 h.DesiredAngle=0 end function moveSit()K.MaxVelocity=.15 M.MaxVelocity=.15 K.DesiredAngle=1.57 M.DesiredAngle=-1.57 b.DesiredAngle=1.57 h.DesiredAngle=-1.57 end function animate(z)local p local N if q=="\074\117\109\112\105\110\103"then moveJump()return end if q=="\070\114\101\101\070\097\108\108"then moveFreeFall()return end if q=="\083\101\097\116\101\100"then moveSit()return end local y=0 if q=="\082\117\110\110\105\110\103"then K.MaxVelocity=.15 M.MaxVelocity=.15 p=1 N=9 elseif q=="\067\108\105\109\098\105\110\103"then K.MaxVelocity=.5 M.MaxVelocity=.5 p=1 N=9 y=3.14 else p=.1 N=1 end desiredAngle=p*math.sin(z*N)if not chasing and N==9 then N=4 end if chasing then K.DesiredAngle=math.pi/2 M.DesiredAngle=-math.pi/2 b.DesiredAngle=-desiredAngle*2 h.DesiredAngle=-desiredAngle*2 else K.DesiredAngle=desiredAngle+y M.DesiredAngle=desiredAngle-y b.DesiredAngle=-desiredAngle h.DesiredAngle=-desiredAngle end end function attack(p,b)if p-lastattack>=1 then local h,N=raycast(z.Position,(b-z.Position).unit,attackrange)if h and(h.Parent~=nil and h.Parent.Name~=sp.Name)then local z=h.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")if z then local p=sp:FindFirstChild("\099\114\101\097\116\111\114")if p then if p.Value~=nil then if p.Value~=game.Players:GetPlayerFromCharacter(z.Parent)then for z,p in ipairs(z:GetChildren())do if p.Name=="\099\114\101\097\116\111\114"then p:remove()end end;(p:clone()).Parent=z else return end end end z:TakeDamage(damage)P.Volume=.5+.5*math.random()P.Pitch=.5+math.random()P:Play()if K and M then K.CurrentAngle=0 M.CurrentAngle=0 end end end lastattack=p end end y.Died:connect(onDied)y.Running:connect(onRunning)y.Jumping:connect(onJumping)y.Climbing:connect(onClimbing)y.GettingUp:connect(onGettingUp)y.FreeFalling:connect(onFreeFall)y.FallingDown:connect(onFallingDown)y.Seated:connect(onSeated)y.PlatformStanding:connect(onPlatformStanding)function populatehumanoids(z)if z.ClassName=="\072\117\109\097\110\111\105\100"then table.insert(humanoids,z)end for z,p in ipairs(z:GetChildren())do populatehumanoids(p)end end function playsound(z)nextsound=(z+5)+math.random()*5 local p=o[math.random(1,#o)]p.Volume=1 p.Pitch=1 p:Play()end while sp.Parent~=nil and(y and(y.Parent~=nil and(y.Health>0 and(z and(p and(z~=nil and z.Parent~=nil))))))do local p,K=wait(.33333333333333)humanoids={}populatehumanoids(game.Workspace)closesttarget=nil closestdist=sightrange local M=sp:FindFirstChild("\099\114\101\097\116\111\114")for p,K in ipairs(humanoids)do if K and K.Parent~=nil then if K.Health>0 and(K.Parent.Name~=sp.Name and K.Parent~=sp)then local p=game.Players:GetPlayerFromCharacter(K.Parent)if M==nil or p==nil or M.Value~=p then local p=K.Parent:FindFirstChild("\084\111\114\115\111")if p~=nil then local K=(p.Position-z.Position).magnitude if K<closestdist then closestdist=K closesttarget=p end end end end end end if closesttarget~=nil then if not chasing then playsound(K)chasing=true y.WalkSpeed=runspeed end y:MoveTo(closesttarget.Position+Vector3.new(1,1,1)*(variance*(math.random()*2-1)),closesttarget)if math.random()<.5 then attack(K,closesttarget.Position)end else if chasing then chasing=false y.WalkSpeed=wonderspeed end if K>nextrandom then nextrandom=(K+3)+math.random()*5 local p=z.Position+(Vector3.new(1,1,1)*math.random()-Vector3.new(.5,.5,.5))*40 y:MoveTo(p,game.Workspace.Terrain)end end if K>nextsound then playsound(K)end if K>nextjump then nextjump=(K+7)+math.random()*5 y.Jump=true end animate(K)end if sp~=nil then for z,p in ipairs(sp:GetChildren())do if p.className=="\080\097\114\116"then p.CanCollide=false end end end wait(4)sp:remove()


local Torso=waitForChild(sp,"Torso")
local Head=waitForChild(sp,"Head")
local RightShoulder=waitForChild(Torso,"Right Shoulder")
local LeftShoulder=waitForChild(Torso,"Left Shoulder")
local RightHip=waitForChild(Torso,"Right Hip")
local LeftHip=waitForChild(Torso,"Left Hip")
local Neck=waitForChild(Torso,"Neck")
local Humanoid=waitForChild(sp,"Humanoid")
local pose="Standing"
local hitsound=waitForChild(Torso,"HitSound")

local sounds={
	waitForChild(Torso,"Ghost1Sound"),
	waitForChild(Torso,"Ghost2Sound"),
}



if healthregen then
	local regenscript=waitForChild(sp,"HealthRegenerationScript")
	regenscript.Disabled=false
end
Humanoid.WalkSpeed=wonderspeed

local toolAnim="None"
local toolAnimTime=0


function onRunning(speed)
	if speed>0 then
		pose="Running"
	else
		pose="Standing"
	end
end
function onDied()
	pose="Dead"
end
function onJumping()
	pose="Jumping"
end
function onClimbing()
	pose="Climbing"
end
function onGettingUp()
	pose = "GettingUp"
end
function onFreeFall()
	pose = "FreeFall"
end
function onFallingDown()
	pose = "FallingDown"
end
function onSeated()
	pose = "Seated"
end
function onPlatformStanding()
	pose = "PlatformStanding"
end

function moveJump()
	RightShoulder.MaxVelocity = 0.5
	LeftShoulder.MaxVelocity = 0.5
  RightShoulder.DesiredAngle=3.14
	LeftShoulder.DesiredAngle=-3.14
	RightHip.DesiredAngle=0
	LeftHip.DesiredAngle=0
end

function moveFreeFall()
	RightShoulder.MaxVelocity = 0.5
	LeftShoulder.MaxVelocity =0.5
	RightShoulder.DesiredAngle=3.14
	LeftShoulder.DesiredAngle=-3.14
	RightHip.DesiredAngle=0
	LeftHip.DesiredAngle=0
end

function moveSit()
	RightShoulder.MaxVelocity = 0.15
	LeftShoulder.MaxVelocity = 0.15
	RightShoulder.DesiredAngle=3.14 /2
	LeftShoulder.DesiredAngle=-3.14 /2
	RightHip.DesiredAngle=3.14 /2
	LeftHip.DesiredAngle=-3.14 /2
end

function animate(time)
	local amplitude
	local frequency
	if (pose == "Jumping") then
		moveJump()
		return
	end
	if (pose == "FreeFall") then
		moveFreeFall()
		return
	end
	if (pose == "Seated") then
		moveSit()
		return
	end
	local climbFudge = 0
	if (pose == "Running") then
		RightShoulder.MaxVelocity = 0.15
		LeftShoulder.MaxVelocity = 0.15
		amplitude = 1
		frequency = 9
	elseif (pose == "Climbing") then
		RightShoulder.MaxVelocity = 0.5 
		LeftShoulder.MaxVelocity = 0.5
		amplitude = 1
		frequency = 9
		climbFudge = 3.14
	else
		amplitude = 0.1
		frequency = 1
	end
	desiredAngle = amplitude * math.sin(time*frequency)
	if not chasing and frequency==9 then
		frequency=4
	end
	if chasing then
		RightShoulder.DesiredAngle=math.pi/2
		LeftShoulder.DesiredAngle=-math.pi/2
		RightHip.DesiredAngle=-desiredAngle*2
		LeftHip.DesiredAngle=-desiredAngle*2
	else
		RightShoulder.DesiredAngle=desiredAngle + climbFudge
		LeftShoulder.DesiredAngle=desiredAngle - climbFudge
		RightHip.DesiredAngle=-desiredAngle
		LeftHip.DesiredAngle=-desiredAngle
	end
end


function attack(time,attackpos)
	if time-lastattack>=1 then
		local hit,pos=raycast(Torso.Position,(attackpos-Torso.Position).unit,attackrange)
		if hit and hit.Parent~=nil and hit.Parent.Name~=sp.Name then
			local h=hit.Parent:FindFirstChild("Humanoid")
			if h then
				local creator=sp:FindFirstChild("creator")
				if creator then
					if creator.Value~=nil then
						if creator.Value~=game.Players:GetPlayerFromCharacter(h.Parent) then
							for i,oldtag in ipairs(h:GetChildren()) do
								if oldtag.Name=="creator" then
									oldtag:remove()
								end
							end
							creator:clone().Parent=h
						else
							return
						end
					end
				end
				h:TakeDamage(damage)
				hitsound.Volume=.5+(.5*math.random())
				hitsound.Pitch=.5+math.random()
				hitsound:Play()
				if RightShoulder and LeftShoulder then
					RightShoulder.CurrentAngle=0
					LeftShoulder.CurrentAngle=0
				end
			end
		end
		lastattack=time
	end
end


Humanoid.Died:connect(onDied)
Humanoid.Running:connect(onRunning)
Humanoid.Jumping:connect(onJumping)
Humanoid.Climbing:connect(onClimbing)
Humanoid.GettingUp:connect(onGettingUp)
Humanoid.FreeFalling:connect(onFreeFall)
Humanoid.FallingDown:connect(onFallingDown)
Humanoid.Seated:connect(onSeated)
Humanoid.PlatformStanding:connect(onPlatformStanding)


function populatehumanoids(mdl)
	if mdl.ClassName=="Humanoid" then
		table.insert(humanoids,mdl)
	end
	for i2,mdl2 in ipairs(mdl:GetChildren()) do
		populatehumanoids(mdl2)
	end
end

function playsound(time)
	nextsound=time+5+(math.random()*5)
	local randomsound=sounds[math.random(1,#sounds)]
	randomsound.Volume=1
	randomsound.Pitch=1
	randomsound:Play()
end

while sp.Parent~=nil and Humanoid and Humanoid.Parent~=nil and Humanoid.Health>0 and Torso and Head and Torso~=nil and Torso.Parent~=nil do
	local _,time=wait(1/3)
	humanoids={}
	populatehumanoids(game.Workspace)
	closesttarget=nil
	closestdist=sightrange
	local creator=sp:FindFirstChild("creator")
	for i,h in ipairs(humanoids) do
		if h and h.Parent~=nil then
			if h.Health>0 and h.Parent.Name~=sp.Name and h.Parent~=sp then
				local plr=game.Players:GetPlayerFromCharacter(h.Parent)
				if creator==nil or plr==nil or creator.Value~=plr then
					local t=h.Parent:FindFirstChild("Torso")
					if t~=nil then
						local dist=(t.Position-Torso.Position).magnitude
						if dist<closestdist then
							closestdist=dist
							closesttarget=t
						end
					end
				end
			end
		end
	end
	if closesttarget~=nil then
		if not chasing then
			playsound(time)
			chasing=true
			Humanoid.WalkSpeed=runspeed
		end
		Humanoid:MoveTo(closesttarget.Position+(Vector3.new(1,1,1)*(variance*((math.random()*2)-1))),closesttarget)
		if math.random()<.5 then
			attack(time,closesttarget.Position)
		end
	else
		if chasing then
			chasing=false
			Humanoid.WalkSpeed=wonderspeed
		end
		if time>nextrandom then
			nextrandom=time+3+(math.random()*5)
			local randompos=Torso.Position+((Vector3.new(1,1,1)*math.random()-Vector3.new(.5,.5,.5))*40)
			Humanoid:MoveTo(randompos,game.Workspace.Terrain)
		end
	end
	if time>nextsound then
		playsound(time)
	end
	if time>nextjump then
		nextjump=time+7+(math.random()*5)
		Humanoid.Jump=true
	end
	animate(time)
end
if sp~=nil then
	for i,v in ipairs(sp:GetChildren()) do
		if v.className=="Part" then
			v.CanCollide=false
		end
	end
end
wait(4)
sp:remove() --Rest In Pizza
