Tool=script.Parent Handle=Tool:WaitForChild("\072\097\110\100\108\101")Players=game:GetService("\080\108\097\121\101\114\115")RunService=game:GetService("\082\117\110\083\101\114\118\105\099\101")Camera=(game:GetService("\087\111\114\107\115\112\097\099\101")).CurrentCamera Animations={}LocalObjects={}ServerControl=Tool:WaitForChild("\083\101\114\118\101\114\067\111\110\116\114\111\108")ClientControl=Tool:WaitForChild("\067\108\105\101\110\116\067\111\110\116\114\111\108")ReloadCounter=0 ToolEquipped=false function SetAnimation(H,J)if H=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(J and(ToolEquipped and Humanoid))then for H,V in pairs(Animations)do if V.Animation==J.Animation then V.AnimationTrack:Stop()table.remove(Animations,H)end end local H=Humanoid:LoadAnimation(J.Animation)table.insert(Animations,{Animation=J.Animation,AnimationTrack=H})H:Play(J.FadeTime,J.Weight,J.Speed)elseif H=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and J then for H,V in pairs(Animations)do if V.Animation==J.Animation then V.AnimationTrack:Stop()table.remove(Animations,H)end end end end function CheckIfAlive()return(Player and(Player.Parent and(Humanoid and(Humanoid.Parent and Humanoid.Health>0))))and true or false end function Equipped(H)Character=Tool.Parent Player=Players:GetPlayerFromCharacter(Character)Humanoid=Character:FindFirstChild("\072\117\109\097\110\111\105\100")ToolEquipped=true if not CheckIfAlive()then return end PlayerMouse=Player:GetMouse()H.Button1Down:connect(function()InvokeServer("\077\111\117\115\101\067\108\105\099\107",{Down=true})end)H.Button1Up:connect(function()InvokeServer("\077\111\117\115\101\067\108\105\099\107",{Down=false})end)H.KeyDown:connect(function(H)InvokeServer("\075\101\121\080\114\101\115\115",{Key=H;Down=true})end)H.KeyUp:connect(function(H)InvokeServer("\075\101\121\080\114\101\115\115",{Key=H;Down=false})end)end function Unequipped()ToolEquipped=false LocalObjects={}for H,J in pairs(Animations)do if J and J.AnimationTrack then J.AnimationTrack:Stop()end end Animations={}end function InvokeServer(H,J)pcall(function()local V=ServerControl:InvokeServer(H,J)return V end)end function OnClientInvoke(H,J)if H=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and(J and(ToolEquipped and Humanoid))then SetAnimation("\080\108\097\121\065\110\105\109\097\116\105\111\110",J)elseif H=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and J then SetAnimation("\083\116\111\112\065\110\105\109\097\116\105\111\110",J)elseif H=="\080\108\097\121\083\111\117\110\100"and J then J:Play()elseif H=="\083\116\111\112\083\111\117\110\100"and J then J:Stop()elseif H=="\077\111\117\115\101\080\111\115\105\116\105\111\110"then return PlayerMouse.Hit.p end end ClientControl.OnClientInvoke=OnClientInvoke Tool.Equipped:connect(Equipped)Tool.Unequipped:connect(Unequipped)


Tool = script.Parent
Handle = Tool:WaitForChild("Handle")

Players = game:GetService("Players")
RunService = game:GetService("RunService")

Camera = game:GetService("Workspace").CurrentCamera

Animations = {}
LocalObjects = {}

ServerControl = Tool:WaitForChild("ServerControl")
ClientControl = Tool:WaitForChild("ClientControl")

ReloadCounter = 0

ToolEquipped = false

function SetAnimation(Mode, Value)
	if Mode == "PlayAnimation" and Value and ToolEquipped and Humanoid then
		for i, v in pairs(Animations) do
			if v.Animation == Value.Animation then
				v.AnimationTrack:Stop()
				table.remove(Animations, i)
			end
		end
		local AnimationTrack = Humanoid:LoadAnimation(Value.Animation)
		table.insert(Animations, {Animation = Value.Animation, AnimationTrack = AnimationTrack})
		AnimationTrack:Play(Value.FadeTime, Value.Weight, Value.Speed)
	elseif Mode == "StopAnimation" and Value then
		for i, v in pairs(Animations) do
			if v.Animation == Value.Animation then
				v.AnimationTrack:Stop()
				table.remove(Animations, i)
			end
		end
	end
end

function CheckIfAlive()
	return (((Player and Player.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0) and true) or false)
end

function Equipped(Mouse)
	Character = Tool.Parent
	Player = Players:GetPlayerFromCharacter(Character)
	Humanoid = Character:FindFirstChild("Humanoid")
	ToolEquipped = true
	if not CheckIfAlive() then
		return
	end
	PlayerMouse = Player:GetMouse()
	Mouse.Button1Down:connect(function()
		InvokeServer("MouseClick", {Down = true})
	end)
	Mouse.Button1Up:connect(function()
		InvokeServer("MouseClick", {Down = false})
	end)
	Mouse.KeyDown:connect(function(Key)
		InvokeServer("KeyPress", {Key = Key, Down = true})
	end)
	Mouse.KeyUp:connect(function(Key)
		InvokeServer("KeyPress", {Key = Key, Down = false})
	end)
end

function Unequipped()
	ToolEquipped = false
	LocalObjects = {}
	for i, v in pairs(Animations) do
		if v and v.AnimationTrack then
			v.AnimationTrack:Stop()
		end
	end
	Animations = {}
end

function InvokeServer(Mode, Value)
	pcall(function()
		local ServerReturn = ServerControl:InvokeServer(Mode, Value)
		return ServerReturn
	end)
end

function OnClientInvoke(Mode, Value)
	if Mode == "PlayAnimation" and Value and ToolEquipped and Humanoid then
		SetAnimation("PlayAnimation", Value)
	elseif Mode == "StopAnimation" and Value then
		SetAnimation("StopAnimation", Value)
	elseif Mode == "PlaySound" and Value then
		Value:Play()
	elseif Mode == "StopSound" and Value then
		Value:Stop()
	elseif Mode == "MousePosition" then
		return PlayerMouse.Hit.p
	end
end

ClientControl.OnClientInvoke = OnClientInvoke
Tool.Equipped:connect(Equipped)
Tool.Unequipped:connect(Unequipped)
