function waitForChild(y,q)while true do local g=y:findFirstChild(q)if g then return g end y.ChildAdded:wait()end end local y=script.Parent local q=waitForChild(y,"\084\111\114\115\111")local g=waitForChild(q,"\082\105\103\104\116 \083\104\111\117\108\100\101\114")local J=waitForChild(q,"\076\101\102\116 \083\104\111\117\108\100\101\114")local m=waitForChild(q,"\082\105\103\104\116 \072\105\112")local p=waitForChild(q,"\076\101\102\116 \072\105\112")local I=waitForChild(q,"\078\101\099\107")local v=waitForChild(y,"\072\117\109\097\110\111\105\100")local Y="\083\116\097\110\100\105\110\103"local a="\078\111\110\101"local P=0 local C=false function onRunning(y)if C then return end if y>0 then Y="\082\117\110\110\105\110\103"else Y="\083\116\097\110\100\105\110\103"end end function onDied()Y="\068\101\097\100"end function onJumping()C=false Y="\074\117\109\112\105\110\103"end function onClimbing()Y="\067\108\105\109\098\105\110\103"end function onGettingUp()Y="\071\101\116\116\105\110\103\085\112"end function onFreeFall()Y="\070\114\101\101\070\097\108\108"end function onDancing()Y="\068\097\110\099\105\110\103"end function onFallingDown()Y="\070\097\108\108\105\110\103\068\111\119\110"end function onSeated()C=true Y="\083\101\097\116\101\100"end function moveJump()g.MaxVelocity=.5 J.MaxVelocity=.5 g.DesiredAngle=-3.14 J.DesiredAngle=-3.14 m.DesiredAngle=0 p.DesiredAngle=0 end function moveFreeFall()g.MaxVelocity=.5 J.MaxVelocity=.5 g.DesiredAngle=-1 J.DesiredAngle=-1 m.DesiredAngle=0 p.DesiredAngle=0 end function moveFloat()g.MaxVelocity=.5 J.MaxVelocity=.5 g.DesiredAngle=-1.57 J.DesiredAngle=1.57 m.DesiredAngle=1.57 p.DesiredAngle=-1.57 end function moveBoogy()while Y=="\066\111\111\103\121"do wait(.5)g.MaxVelocity=1 J.MaxVelocity=1 g.DesiredAngle=-3.14 J.DesiredAngle=0 m.DesiredAngle=1.57 p.DesiredAngle=0 wait(.5)g.MaxVelocity=1 J.MaxVelocity=1 g.DesiredAngle=0 J.DesiredAngle=-3.14 m.DesiredAngle=0 p.DesiredAngle=1.57 end end function moveZombie()g.MaxVelocity=.5 J.MaxVelocity=.5 g.DesiredAngle=-1.57 J.DesiredAngle=1.57 m.DesiredAngle=0 p.DesiredAngle=0 end function movePunch()script.Parent.Torso.Anchored=true g.MaxVelocity=60 J.MaxVelocity=.5 g.DesiredAngle=-1.57 J.DesiredAngle=0 m.DesiredAngle=0 p.DesiredAngle=0 wait(1)script.Parent.Torso.Anchored=false Y="\083\116\097\110\100\105\110\103"end function moveKick()g.MaxVelocity=.5 J.MaxVelocity=.5 g.DesiredAngle=0 J.DesiredAngle=0 m.MaxVelocity=40 m.DesiredAngle=1.57 p.DesiredAngle=0 wait(1)Y="\083\116\097\110\100\105\110\103"end function moveFly()g.MaxVelocity=.5 J.MaxVelocity=.5 g.DesiredAngle=0 J.DesiredAngle=0 m.MaxVelocity=40 m.DesiredAngle=1.57 p.DesiredAngle=0 wait(1)Y="\083\116\097\110\100\105\110\103"end function moveClimb()g.MaxVelocity=.5 J.MaxVelocity=.5 g.DesiredAngle=-3.14 J.DesiredAngle=3.14 m.DesiredAngle=0 p.DesiredAngle=0 end function moveSit()g.MaxVelocity=.15 J.MaxVelocity=.15 g.DesiredAngle=-1.57 J.DesiredAngle=-1.57 m.DesiredAngle=1.57 p.DesiredAngle=-1.57 end function getTool()kidTable=y:children()if kidTable~=nil then numKids=#kidTable for y=1,numKids,1 do if kidTable[y].className=="\084\111\111\108"then return kidTable[y]end end end return nil end function getToolAnim(y)c=y:children()for y=1,#c,1 do if c[y].Name=="\116\111\111\108\097\110\105\109"and c[y].className=="\083\116\114\105\110\103\086\097\108\117\101"then return c[y]end end return nil end function animateTool()if a=="\078\111\110\101"then g.DesiredAngle=-1.57 return end if a=="\083\108\097\115\104"then g.MaxVelocity=.5 g.DesiredAngle=0 return end if a=="\076\117\110\103\101"then g.MaxVelocity=.5 J.MaxVelocity=.5 m.MaxVelocity=.5 p.MaxVelocity=.5 g.DesiredAngle=-1.57 J.DesiredAngle=1.0 m.DesiredAngle=1.57 p.DesiredAngle=1.0 return end end function move(y)local q local I if Y=="\074\117\109\112\105\110\103"then moveJump()return end if Y=="\090\111\109\098\105\101"then moveZombie()return end if Y=="\066\111\111\103\121"then moveBoogy()return end if Y=="\070\108\111\097\116"then moveFloat()return end if Y=="\080\117\110\099\104"then movePunch()return end if Y=="\075\105\099\107"then moveKick()return end if Y=="\070\108\121"then moveFly()return end if Y=="\070\114\101\101\070\097\108\108"then moveFreeFall()return end if Y=="\067\108\105\109\098\105\110\103"then moveClimb()return end if Y=="\083\101\097\116\101\100"then moveSit()return end q=.1 I=1 g.MaxVelocity=.15 J.MaxVelocity=.15 if Y=="\082\117\110\110\105\110\103"then q=1 I=9 elseif Y=="\068\097\110\099\105\110\103"then q=2 I=16 end desiredAngle=q*math.sin(y*I)if Y~="\068\097\110\099\105\110\103"then g.DesiredAngle=-desiredAngle J.DesiredAngle=desiredAngle m.DesiredAngle=-desiredAngle p.DesiredAngle=-desiredAngle else g.DesiredAngle=desiredAngle J.DesiredAngle=desiredAngle m.DesiredAngle=-desiredAngle p.DesiredAngle=-desiredAngle end local v=getTool()if v~=nil then animStringValueObject=getToolAnim(v)if animStringValueObject~=nil then a=animStringValueObject.Value animStringValueObject.Parent=nil P=y+.3 end if y>P then P=0 a="\078\111\110\101"end animateTool()else a="\078\111\110\101"P=0 end end



function waitForChild(parent, childName)
	while true do
		local child = parent:findFirstChild(childName)
		if child then
			return child
		end
		parent.ChildAdded:wait()
	end
end

local Figure = script.Parent
local Torso = waitForChild(Figure, "Torso")
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(Figure, "Humanoid")
local pose = "Standing"

local toolAnim = "None"
local toolAnimTime = 0

local isSeated = false


function onRunning(speed)
	if isSeated then return end

	if speed>0 then
		pose = "Running"
	else
		pose = "Standing"
	end
end

function onDied()
	pose = "Dead"
end

function onJumping()
	isSeated = false
	pose = "Jumping"
end

function onClimbing()
	pose = "Climbing"
end

function onGettingUp()
	pose = "GettingUp"
end

function onFreeFall()
	pose = "FreeFall"
end

function onDancing()
	pose = "Dancing"
end

function onFallingDown()
	pose = "FallingDown"
end

function onSeated()
	isSeated = true
	pose = "Seated"
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 = -1
	LeftShoulder.DesiredAngle = -1
	RightHip.DesiredAngle = 0
	LeftHip.DesiredAngle = 0
end

function moveFloat()
	RightShoulder.MaxVelocity = 0.5
	LeftShoulder.MaxVelocity = 0.5
	RightShoulder.DesiredAngle = -1.57
	LeftShoulder.DesiredAngle = 1.57
	RightHip.DesiredAngle = 1.57
	LeftHip.DesiredAngle = -1.57
end

function moveBoogy()
while pose=="Boogy" do
	wait(.5)
	RightShoulder.MaxVelocity = 1
	LeftShoulder.MaxVelocity = 1
	RightShoulder.DesiredAngle = -3.14
	LeftShoulder.DesiredAngle = 0
	RightHip.DesiredAngle = 1.57
	LeftHip.DesiredAngle = 0
	wait(.5)
	RightShoulder.MaxVelocity = 1
	LeftShoulder.MaxVelocity = 1
	RightShoulder.DesiredAngle = 0
	LeftShoulder.DesiredAngle = -3.14
	RightHip.DesiredAngle = 0
	LeftHip.DesiredAngle = 1.57
end
end

function moveZombie()
	RightShoulder.MaxVelocity = 0.5
	LeftShoulder.MaxVelocity = 0.5
	RightShoulder.DesiredAngle = -1.57
	LeftShoulder.DesiredAngle = 1.57
	RightHip.DesiredAngle = 0
	LeftHip.DesiredAngle = 0
end

function movePunch()
	script.Parent.Torso.Anchored=true
	RightShoulder.MaxVelocity = 60
	LeftShoulder.MaxVelocity = 0.5
	RightShoulder.DesiredAngle = -1.57
	LeftShoulder.DesiredAngle = 0
	RightHip.DesiredAngle = 0
	LeftHip.DesiredAngle = 0
wait(1)
script.Parent.Torso.Anchored=false
pose="Standing"

end

function moveKick()
	RightShoulder.MaxVelocity = 0.5
	LeftShoulder.MaxVelocity = 0.5
	RightShoulder.DesiredAngle = 0
	LeftShoulder.DesiredAngle = 0
	RightHip.MaxVelocity = 40
	RightHip.DesiredAngle = 1.57
	LeftHip.DesiredAngle = 0
wait(1)
pose="Standing"

end

function moveFly()
	RightShoulder.MaxVelocity = 0.5
	LeftShoulder.MaxVelocity = 0.5
	RightShoulder.DesiredAngle = 0
	LeftShoulder.DesiredAngle = 0
	RightHip.MaxVelocity = 40
	RightHip.DesiredAngle = 1.57
	LeftHip.DesiredAngle = 0
wait(1)
pose="Standing"

end


function moveClimb()
	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 getTool()
	
	kidTable = Figure:children()
	if (kidTable ~= nil) then
		numKids = #kidTable
		for i=1,numKids do
			if (kidTable[i].className == "Tool") then return kidTable[i] end
		end
	end
	
	return nil
end

function getToolAnim(tool)

	c = tool:children()
	for i=1,#c do
		if (c[i].Name == "toolanim" and c[i].className == "StringValue") then
			return c[i]
		end
	end
	return nil
end

function animateTool()
	
	if (toolAnim == "None") then
		RightShoulder.DesiredAngle = -1.57
		return
	end

	if (toolAnim == "Slash") then
		RightShoulder.MaxVelocity = 0.5
		RightShoulder.DesiredAngle = 0
		return
	end

	if (toolAnim == "Lunge") then
		RightShoulder.MaxVelocity = 0.5
		LeftShoulder.MaxVelocity = 0.5
		RightHip.MaxVelocity = 0.5
		LeftHip.MaxVelocity = 0.5
		RightShoulder.DesiredAngle = -1.57
		LeftShoulder.DesiredAngle = 1.0
		RightHip.DesiredAngle = 1.57
		LeftHip.DesiredAngle = 1.0
		return
	end
end

function move(time)
	local amplitude
	local frequency

	if (pose == "Jumping") then
		moveJump()
		return
	end

	if (pose == "Zombie") then
		moveZombie()
		return
	end

	if (pose == "Boogy") then
		moveBoogy()
		return
	end

	if (pose == "Float") then
		moveFloat()
		return
	end

	if (pose == "Punch") then
		movePunch()
		return
	end

	if (pose == "Kick") then
		moveKick()
		return
	end

	if (pose == "Fly") then
		moveFly()
		return
	end

	if (pose == "FreeFall") then
		moveFreeFall()
		return
	end

	if (pose == "Climbing") then
		moveClimb()
		return
	end

	if (pose == "Seated") then
		moveSit()
		return
	end

		amplitude = 0.1
		frequency = 1

	RightShoulder.MaxVelocity = 0.15
	LeftShoulder.MaxVelocity = 0.15
	if (pose == "Running") then
		amplitude = 1
		frequency = 9
	elseif (pose == "Dancing") then
		amplitude = 2
		frequency = 16
	end


	desiredAngle = amplitude * math.sin(time*frequency)
	if pose~="Dancing" then
		RightShoulder.DesiredAngle = -desiredAngle
		LeftShoulder.DesiredAngle = desiredAngle
		RightHip.DesiredAngle = -desiredAngle
		LeftHip.DesiredAngle = -desiredAngle
	else
		RightShoulder.DesiredAngle = desiredAngle
		LeftShoulder.DesiredAngle = desiredAngle
		RightHip.DesiredAngle = -desiredAngle
		LeftHip.DesiredAngle = -desiredAngle
	end
		


	local tool = getTool()

	if tool ~= nil then
	
		animStringValueObject = getToolAnim(tool)

		if animStringValueObject ~= nil then
			toolAnim = animStringValueObject.Value
			-- message recieved, delete StringValue
			animStringValueObject.Parent = nil
			toolAnimTime = time + .3
		end

		if time > toolAnimTime then
			toolAnimTime = 0
			toolAnim = "None"
		end

		animateTool()

		
	else
		toolAnim = "None"
		toolAnimTime = 0
	end
end

