ClientControl.OnClientInvoke=function(g,T)if g=="\080\108\097\121\065\110\105\109\097\116\105\111\110"and Humanoid then for g,X in pairs(Animations)do if X.Animation==T.Animation then X.AnimationTrack:Stop()table.remove(Animations,g)end end local g=Humanoid:LoadAnimation(T.Animation)table.insert(Animations,{Animation=T.Animation,AnimationTrack=g})g:Play(T.FadeTime,T.Weight,T.Speed)elseif g=="\083\116\111\112\065\110\105\109\097\116\105\111\110"and T then for g,X in pairs(Animations)do if X.Animation==T.Animation then X.AnimationTrack:Stop()table.remove(Animations,g)end end elseif g=="\080\114\101\108\111\097\100"and T then ContentProvider:Preload(T)elseif g=="\080\108\097\121\083\111\117\110\100"and T then T:Play()elseif g=="\083\116\111\112\083\111\117\110\100"and T then T:Stop()elseif g=="\077\111\117\115\101\080\111\115\105\116\105\111\110"then return PlayerMouse.Hit.p end end function InvokeServer(g,T)pcall(function()local X=ServerControl:InvokeServer(g,T)return X end)end function CheckIfAlive()return Player and(Player.Parent and(Humanoid and(Humanoid.Parent and Humanoid.Health>0)))end function Equipped(g)Character=Tool.Parent Player=Players:GetPlayerFromCharacter(Character)Humanoid=Character:FindFirstChild("\072\117\109\097\110\111\105\100")if not CheckIfAlive()then return end PlayerMouse=Player:GetMouse()g.Button1Down:connect(function()InvokeServer("\077\111\117\115\101\067\108\105\099\107",{Down=true})end)g.Button1Up:connect(function()InvokeServer("\077\111\117\115\101\067\108\105\099\107",{Down=false})end)g.KeyDown:connect(function(g)InvokeServer("\075\101\121\080\114\101\115\115",{Key=g;Down=true})end)g.KeyUp:connect(function(g)InvokeServer("\075\101\121\080\114\101\115\115",{Key=g,Down=false})end)end function Unequipped()for g,T in pairs(Animations)do if T and T.AnimationTrack then T.AnimationTrack:Stop()end end Animations={}end Tool.Equipped:connect(Equipped)Tool.Unequipped:connect(Unequipped)
---------------------------------------------------------------------------------------------------------------------------
-- Functions
---------------------------------------------------------------------------------------------------------------------------

ClientControl.OnClientInvoke = function(Mode, Value)
	if Mode == "PlayAnimation" 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
	elseif Mode == "Preload" and Value then
		ContentProvider:Preload(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

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

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

function Equipped(Mouse)
	Character = Tool.Parent
	Player = Players:GetPlayerFromCharacter(Character)
	Humanoid = Character:FindFirstChild("Humanoid")
	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()
	for i, v in pairs(Animations) do
		if v and v.AnimationTrack then
			v.AnimationTrack:Stop()
		end
	end
	Animations = {}
end

Tool.Equipped:connect(Equipped)
Tool.Unequipped:connect(Unequipped)
