function waitForChild(X,G)while true do local E=X:findFirstChild(G)if E then return E end X.ChildAdded:wait()end end local X=script.Parent local G=waitForChild(X,"\084\111\114\115\111")local E=waitForChild(G,"\082\105\103\104\116 \083\104\111\117\108\100\101\114")local m=waitForChild(G,"\076\101\102\116 \083\104\111\117\108\100\101\114")local C=waitForChild(G,"\082\105\103\104\116 \072\105\112")local a=waitForChild(G,"\076\101\102\116 \072\105\112")local h=waitForChild(G,"\078\101\099\107")local B=waitForChild(X,"\072\117\109\097\110\111\105\100")local l="\083\116\097\110\100\105\110\103"local K="\078\111\110\101"local I=0 local Q=false function newSound(X,G)local E=script.Parent.Head:findFirstChild(X)if E==nil then E=Instance.new("\083\111\117\110\100")E.Name=X E.Parent=script.Parent.Head E.SoundId=G end return E end local g=newSound("\068\105\101\100","\114\098\120\097\115\115\101\116\058\047\047\115\111\117\110\100\115\047\117\117\104\104\104\046\119\097\118")local y=newSound("\070\097\108\108\105\110\103\068\111\119\110","\114\098\120\097\115\115\101\116\058\047\047\115\111\117\110\100\115\047\115\112\108\097\116\046\119\097\118")local u=newSound("\070\114\101\101\070\097\108\108\105\110\103","\114\098\120\097\115\115\101\116\058\047\047\115\111\117\110\100\115\047\115\119\111\111\115\104\046\119\097\118")local q=newSound("\071\101\116\116\105\110\103\085\112","\114\098\120\097\115\115\101\116\058\047\047\115\111\117\110\100\115\047\104\105\116\046\119\097\118")local b=newSound("\074\117\109\112\105\110\103","\114\098\120\097\115\115\101\116\058\047\047\115\111\117\110\100\115\047\098\117\116\116\111\110\046\119\097\118")local i=newSound("\082\117\110\110\105\110\103","\114\098\120\097\115\115\101\116\058\047\047\115\111\117\110\100\115\047\098\102\115\108-\109\105\110\105\102\105\103\102\111\111\116\115\049\046\109\112\051")i.Looped=true local p=script.Parent local R=waitForChild(p,"\072\101\097\100")local f=waitForChild(p,"\072\117\109\097\110\111\105\100")function onState(X,G)if X then G:play()else G:pause()end end function onRunning(X)if Q then return end if script.Parent.Attacking.Value==true then return end if X>0 then i:play()l="\082\117\110\110\105\110\103"else i:pause()l="\083\116\097\110\100\105\110\103"end end function onDied()l="\068\101\097\100"g:play()wait(regentime)wait(1)model:remove()model=backup:Clone()wait(3)model.Parent=game.Workspace model:MakeJoints()end function onJumping()Q=false l="\074\117\109\112\105\110\103"end function onClimbing()l="\067\108\105\109\098\105\110\103"end function onGettingUp()l="\071\101\116\116\105\110\103\085\112"end function onFreeFall()l="\070\114\101\101\070\097\108\108"end function onDancing()l="\068\097\110\099\105\110\103"end function onFallingDown()l="\070\097\108\108\105\110\103\068\111\119\110"end function onSeated()Q=true l="\083\101\097\116\101\100"end function moveJump()E.MaxVelocity=1 m.MaxVelocity=1 E.DesiredAngle=-3.14 m.DesiredAngle=-3.14 C.DesiredAngle=0 a.DesiredAngle=0 end function moveFreeFall()E.MaxVelocity=.5 m.MaxVelocity=.5 E.DesiredAngle=-1 m.DesiredAngle=-1 C.DesiredAngle=0 a.DesiredAngle=0 end function moveFloat()E.MaxVelocity=.5 m.MaxVelocity=.5 E.DesiredAngle=-1.57 m.DesiredAngle=1.57 C.DesiredAngle=1.57 a.DesiredAngle=-1.57 end function moveBoogy()while l=="\066\111\111\103\121"do wait(.5)E.MaxVelocity=1 m.MaxVelocity=1 E.DesiredAngle=-3.14 m.DesiredAngle=0 C.DesiredAngle=1.57 a.DesiredAngle=0 wait(.5)E.MaxVelocity=1 m.MaxVelocity=1 E.DesiredAngle=0 m.DesiredAngle=-3.14 C.DesiredAngle=0 a.DesiredAngle=1.57 end end function moveZombie()E.MaxVelocity=.5 m.MaxVelocity=.5 E.DesiredAngle=-1.57 m.DesiredAngle=1.57 C.DesiredAngle=0 a.DesiredAngle=0 end function StandFire()E.MaxVelocity=.5 m.MaxVelocity=.5 E.DesiredAngle=1.57 m.DesiredAngle=0 C.MaxVelocity=.5 a.MaxVelocity=.5 C.DesiredAngle=0 a.DesiredAngle=0 end function movePunch()script.Parent.Torso.Anchored=true E.MaxVelocity=60 m.MaxVelocity=.5 E.DesiredAngle=-1.57 m.DesiredAngle=0 C.DesiredAngle=0 a.DesiredAngle=0 wait(1)script.Parent.Torso.Anchored=false l="\083\116\097\110\100\105\110\103"end function moveKick()E.MaxVelocity=.5 m.MaxVelocity=.5 E.DesiredAngle=0 m.DesiredAngle=0 C.MaxVelocity=40 C.DesiredAngle=1.57 a.DesiredAngle=0 wait(1)l="\083\116\097\110\100\105\110\103"end function moveFly()E.MaxVelocity=.5 m.MaxVelocity=.5 E.DesiredAngle=0 m.DesiredAngle=0 C.MaxVelocity=40 C.DesiredAngle=1.57 a.DesiredAngle=0 wait(1)l="\083\116\097\110\100\105\110\103"end function moveClimb()E.MaxVelocity=.5 m.MaxVelocity=.5 E.DesiredAngle=-3.14 m.DesiredAngle=3.14 C.DesiredAngle=0 a.DesiredAngle=0 end function moveSit()E.MaxVelocity=.15 m.MaxVelocity=.15 E.DesiredAngle=1.57 m.DesiredAngle=-1.57 C.DesiredAngle=1.57 a.DesiredAngle=-1.57 end function getTool()kidTable=p:children()if kidTable~=nil then numKids=#kidTable for X=1,numKids,1 do if kidTable[X].className=="\084\111\111\108"then return kidTable[X]end end end return nil end function getToolAnim(X)c=X:children()for X=1,#c,1 do if c[X].Name=="\116\111\111\108\097\110\105\109"and c[X].className=="\083\116\114\105\110\103\086\097\108\117\101"then return c[X]end end return nil end function animateTool()if K=="\078\111\110\101"then E.DesiredAngle=-1.57 return end if K=="\083\108\097\115\104"then E.MaxVelocity=.5 E.DesiredAngle=0 return end if K=="\076\117\110\103\101"then E.MaxVelocity=.5 m.MaxVelocity=.5 C.MaxVelocity=.5 a.MaxVelocity=.5 E.DesiredAngle=-1.57 m.DesiredAngle=1.0 C.DesiredAngle=1.57 a.DesiredAngle=1.0 return end end function move(X)local G local h local B=script.Parent.Attacking.Value if B==true then l="\097\116\116\097\099\107"script.Parent.Humanoid.WalkSpeed=0 script.Parent.Gun.canFire.Value=true else script.Parent.Humanoid.WalkSpeed=16 script.Parent.Gun.canFire.Value=false end if l=="\097\116\116\097\099\107"then StandFire()return end if l=="\074\117\109\112\105\110\103"then moveJump()return end if l=="\090\111\109\098\105\101"then moveZombie()return end if l=="\066\111\111\103\121"then moveBoogy()return end if l=="\070\108\111\097\116"then moveFloat()return end if l=="\080\117\110\099\104"then movePunch()return end if l=="\075\105\099\107"then moveKick()return end if l=="\070\108\121"then moveFly()return end if l=="\070\114\101\101\070\097\108\108"then moveFreeFall()return end if l=="\067\108\105\109\098\105\110\103"then moveClimb()return end if l=="\083\101\097\116\101\100"then moveSit()return end G=.1 h=1 E.MaxVelocity=.15 m.MaxVelocity=.15 if l=="\082\117\110\110\105\110\103"then G=1 h=9 elseif l=="\068\097\110\099\105\110\103"then G=2 h=16 end desiredAngle=G*math.sin(X*h)if l~="\068\097\110\099\105\110\103"then E.DesiredAngle=desiredAngle m.DesiredAngle=desiredAngle C.DesiredAngle=-desiredAngle a.DesiredAngle=-desiredAngle else E.DesiredAngle=desiredAngle m.DesiredAngle=desiredAngle C.DesiredAngle=-desiredAngle a.DesiredAngle=-desiredAngle end local Q=getTool()if Q~=nil then animStringValueObject=getToolAnim(Q)if animStringValueObject~=nil then K=animStringValueObject.Value animStringValueObject.Parent=nil I=X+.3 end if X>I then I=0 K="\078\111\110\101"end animateTool()else K="\078\111\110\101"I=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 newSound(SndName,id)
	local sound = script.Parent.Head:findFirstChild(SndName)
	if(sound == nil) then
		sound = Instance.new("Sound")
		sound.Name = SndName
		sound.Parent = script.Parent.Head
		sound.SoundId = id	
	end
	return sound
end

local sDied = newSound("Died","rbxasset://sounds/uuhhh.wav")
local sFallingDown = newSound("FallingDown","rbxasset://sounds/splat.wav")
local sFreeFalling = newSound("FreeFalling","rbxasset://sounds/swoosh.wav")
local sGettingUp = newSound("GettingUp","rbxasset://sounds/hit.wav")
local sJumping = newSound("Jumping","rbxasset://sounds/button.wav")
local sRunning = newSound("Running","rbxasset://sounds/bfsl-minifigfoots1.mp3")
sRunning.Looped = true

local Figure = script.Parent
local Head = waitForChild(Figure, "Head")
local Humanoid = waitForChild(Figure, "Humanoid")

function onState(state, sound)
	if state then
		sound:play()
	else
		sound:pause()
	end
end

function onRunning(speed)
	if isSeated then return end
	if(script.Parent.Attacking.Value == true) then return end
	if speed>0 then
		sRunning:play()
		pose = "Running"
	else
		sRunning:pause()
		pose = "Standing"
	end
end

function onDied()
	pose = "Dead"
	sDied:play()
        wait(regentime)
    wait(1)
    model:remove()
    model = backup:Clone()
    wait(3)
    model.Parent = game.Workspace
    model:MakeJoints()
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 = 1
	LeftShoulder.MaxVelocity = 1
	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 StandFire()
	RightShoulder.MaxVelocity = 0.5
	LeftShoulder.MaxVelocity = 0.5
	RightShoulder.DesiredAngle = 1.57
	LeftShoulder.DesiredAngle = 0
	RightHip.MaxVelocity = 0.5
	LeftHip.MaxVelocity = 0.5
	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
	local attack = script.Parent.Attacking.Value
	if(attack == true) then
		pose = "attack"
		script.Parent.Humanoid.WalkSpeed = 0
		script.Parent.Gun.canFire.Value = true
	else
		script.Parent.Humanoid.WalkSpeed = 16
		script.Parent.Gun.canFire.Value =false
	end
	if(pose == "attack") then
		StandFire()
		return
	end
	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
