local q,U Tool.Equipped:connect(function(Q)Character=Tool.Parent Player=game.Players:GetPlayerFromCharacter(Character)local T=(WaitFor(Tool)).HoldAnim()T.AnimationId="\104\116\116\112\058\047\047\119\119\119\046\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061\056\056\055\052\051\053\057\050"local R=(WaitFor(Tool)).ThrowAnim()R.AnimationId="\104\116\116\112\058\047\047\119\119\119\046\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061\056\056\055\052\051\053\054\054"q=Character.Humanoid:LoadAnimation(T)U=Character.Humanoid:LoadAnimation(R)if Now()>NextFireAt.Value then Handle.Transparency=0 Q.Icon="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\092\071\117\110\067\117\114\115\111\114\046\112\110\103"q:Play()else Handle.Transparency=1 Delay(NextFireAt.Value-Now(),function()Q.Icon="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\092\071\117\110\087\097\105\116\067\117\114\115\111\114\046\112\110\103"Handle.Transparency=0 q:Play()end)end Q.Button1Down:connect(function()if Now()>NextFireAt.Value then NextFireAt.Value=Now()+RELOAD_TIME local T=Handle:Clone()T.CanCollide=false local R=GrenadeScript:Clone()R.Parent=T R.Disabled=false;((WaitFor(R)).creator()).Value=Player local D=Q.Hit.p-T.Position local L=D.y D=Vector3.new(D.x,0,D.z)local Z=D.magnitude D=D.unit Velocity=math.min(120,40+Z)local e=computeLaunchAngle(Z,L,196.2)local J=math.sin(e)*Velocity local a=(D.x*math.cos(e))*Velocity local S=(D.z*math.cos(e))*Velocity T.CanCollide=false Delay(.1,function()T.CanCollide=true end)T.Velocity=Vector3.new(a,J,S)T.Parent=game.Workspace ThrowSound:Play()q:Stop(0)U:Play(0,1,1)Handle.Transparency=1 Q.Icon="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\092\071\117\110\087\097\105\116\067\117\114\115\111\114\046\112\110\103"wait(RELOAD_TIME)q:Play()Handle.Transparency=0 Q.Icon="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\092\071\117\110\067\117\114\115\111\114\046\112\110\103"end end)end)Tool.Unequipped:connect(function()if ThrowSound then ThrowSound:Stop()end if U then U:Stop()end if q then q:Stop()end end)
---------------------------------------------

local HoldAnim, ThrowAnim

Tool.Equipped:connect(function(mouse)
	Character = Tool.Parent
	Player = game.Players:GetPlayerFromCharacter(Character)

	local HoldAnimSrc = WaitFor(Tool).HoldAnim()
	HoldAnimSrc.AnimationId = "http://www.roblox.com/asset/?id=88743592"
	local ThrowAnimSrc = WaitFor(Tool).ThrowAnim()
	ThrowAnimSrc.AnimationId = "http://www.roblox.com/asset/?id=88743566"

	HoldAnim = Character.Humanoid:LoadAnimation(HoldAnimSrc)
	ThrowAnim = Character.Humanoid:LoadAnimation(ThrowAnimSrc)

	--setup first anim / cursor cycle
	if Now() > NextFireAt.Value then
		Handle.Transparency = 0
		mouse.Icon = "rbxasset://textures\\GunCursor.png"
		HoldAnim:Play()
	else
		Handle.Transparency = 1
		Delay(NextFireAt.Value - Now(), function()
			mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
			Handle.Transparency = 0
			HoldAnim:Play()
		end)
	end

	mouse.Button1Down:connect(function()
		--we track the reload time like this so that the player can't fire faster with
		--rapid dis / re-equipping, which will actually be common usage with this gear.
		if Now() > NextFireAt.Value then
			NextFireAt.Value = Now() + RELOAD_TIME
			--
			local gr = Handle:Clone()
			gr.CanCollide = false
			local sc = GrenadeScript:Clone()
			sc.Parent = gr
			sc.Disabled = false
			WaitFor(sc).creator().Value = Player

			--calc velocity
			local toTarget = mouse.Hit.p - gr.Position
			local dy = toTarget.y
			toTarget = Vector3.new(toTarget.x, 0, toTarget.z)
			local dx = toTarget.magnitude
			toTarget = toTarget.unit

			Velocity = math.min(120, 40 + dx)

			local theta = computeLaunchAngle(dx, dy, 196.2)

			local vY = math.sin(theta) * Velocity
			local vX = toTarget.x * math.cos(theta) * Velocity
			local vZ = toTarget.z * math.cos(theta) * Velocity

			gr.CanCollide = false
			Delay(0.1, function()
				gr.CanCollide = true
			end)
			gr.Velocity = Vector3.new(vX, vY, vZ)
			gr.Parent = game.Workspace

			--play sound / anim
			ThrowSound:Play()
			HoldAnim:Stop(0)
			ThrowAnim:Play(0, 1, 1)

			--reload
			Handle.Transparency = 1
			mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
			wait(RELOAD_TIME)
			HoldAnim:Play()
			Handle.Transparency = 0
			mouse.Icon = "rbxasset://textures\\GunCursor.png"
		end
	end)
end)

Tool.Unequipped:connect(function()
	if ThrowSound then
		ThrowSound:Stop()
	end
	if ThrowAnim then
		ThrowAnim:Stop()
	end
	if HoldAnim then
		HoldAnim:Stop()
	end
end)
